Partager via


Walkthrough: Creating a Menu Command By Using the Visual Studio Package Template

The Visual Studio Package project template creates a basic VSPackage. The template can add code to create a menu command or a tool window.

Prerequisites

To follow this walkthrough, you must install the Visual Studio 2013 SDK. For more information, see Visual Studio Software Development Kit (SDK).

Locations for the Visual Studio Package Project Template

The Visual Studio Package project template is available in these locations in the New Project dialog box:

  • Under Visual Basic Extensibility. By default, the language of the project is Visual Basic.

  • Under C# Extensibility. By default, the language of the project is C#.

  • Under Other Project Types Extensibility. By default, the language of the project is C++.

To create a VSPackage by using the Visual Studio Package project template

  1. Select the Visual Studio Package project template. In the Name box, type a name for the solution and then click OK.

  2. On the Select a Programming Language page, select either Visual C# or Visual Basic. Have the template generate a key.snk file to sign the assembly. Alternatively, click Browse to select your own key file. The template makes a copy of your key file and names it key.snk.

  3. On the Basic VSPackage Information page, specify details about your VSPackage.

  4. Click Next to specify package options for your VSPackage.

  5. Select the Menu Command option to create a command for your VSPackage. The new command is put at the top of the Tools menu. When the Menu Command option is selected, the Command Options page is displayed after you click Next.

    1. In the Command Name box, type a name for the new command.

      If you later want to host the command as a button on the toolbar, this name is also used as the tooltip for the button.

    2. In the Command ID box, type the command ID for your command.

      The command ID is the name of a constant that represents this command in the generated code.

    3. Click Next to select test project options.

  6. Optionally, select Integration Test Project and Unit Test Project to create test projects for your solution.

  7. Click Finish to create your VSPackage.

To test your menu command

  1. Build the solution, and then start the experimental build of Visual Studio by pressing F5.

  2. On the Tools menu, click your command. A message that has the following text is displayed:

    <VSPackage name>,

    Inside vsip.<Project name>.<VSPackage name>.Exec().

Compiling the Code

Projects generated by the package wizard refer to particular build and deployment paths. If you copy the project to another computer, make sure that the paths are valid.

See Also

Other Resources

VSPackages