Share via


Walkthrough: Adding a Command to a Visual Studio Menu

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

This walkthrough demonstrates how to generate a VSPackage that puts a command on the Tools menu in the Visual Studio integrated development environment (IDE). This walkthrough shows how to do the following tasks by using the Visual Studio Integration Package Wizard:

  • Create a VSPackage in Visual C++ or a managed VSPackage in Visual C# or Visual Basic.

  • Add a menu command to the VSPackage.

  • Build the VSPackage that is generated by the wizard.

When you complete the walkthrough, you will have a basic VSPackage that is correctly registered in the Visual Studio experimental hive and a new command at the top of the Tools menu.

Creating a VSPackage

To create a VSPackage

  1. On the File menu, point to New and then click New Project.

  2. In the New Project dialog box, do the following things:

    1. Under Project Types, expand Other Project Types, and then click Extensibility.

    2. Under Templates, click Visual Studio Integration Package.

    3. In the Name box, type a name for your VSPackage.

    4. To change the location where the solution files will be generated, type a new location in the Location box, or click Browse to select the location from a folder browser.

    5. Click OK to start the Visual Studio Integration Package Wizard.

  3. Read the information about the Welcome to the Visual Studio Integration Package Wizard page, and then click Next.

  4. On the Select a Programming Language page, under Choose Language, select the language in which to develop the VSPackage.

    For Visual C# or Visual Basic, you can either have the wizard generate a key file to sign the assembly for you, or you can browse for your own key file.

  5. On the Basic VSPackage Information page, in the appropriate text boxes, type the name of your company, your VSPackage name and version, and detailed information about the VSPackage. Select the minimum Visual Studio edition you want your VSPackage to support from the Minimum Visual Studio Edition list.

    The VSPackage name is displayed on the Visual Studio splash screen, in the Help About dialog box, and in the VSPackage registry. The version information is displayed in the Help About dialog box and in the VSPackage registry.

    The icon for your VSPackage is displayed on the splash screen and in the Help About dialog box. To select an icon that differs from the default icon that is displayed on the wizard page, click Change Icon. In the Change Icon dialog box, click Browse to select an icon from another location on the computer.

  6. On the Select VSPackage Options page, select Menu Command.

  7. On the Command Options page, type the name and command ID for your command. Click Finish to generate your VSPackage.

Testing Your VSPackage

When you build your VSPackage, the build process merges the UI elements and registers the generated VSPackage in an instance of the Visual Studio experimental environment.

To test the VSPackage

  1. Press F5 to build your VSPackage and start an instance of the Visual Studio experimental environment in debug mode.

    If your VSPackage is generated in Visual C# or Visual Basic, the build process signs the VSPackage assembly by using the key file that the wizard generates, or that you supply. For more information about assembly signing, see How to: Sign an Assembly with a Strong Name.

  2. In the Visual Studio experimental environment, your command is displayed on the Tools menu, together with the icon you chose. When you click the command, a message box appears and displays the following text.

    Language

    Message Text

    Visual C++

    Inside CPackage namePackage::Exec

    Visual Basic

    Inside Project namePackage.MenuItemCallback()

    Visual C#

    Inside Company.Project name.Project namePackage.MenuItemCallback()

  3. To implement your command, update the command handler in the package file. The following table lists the name of the package file for each language.

    Language

    File

    Visual C++

    Package.h

    Visual Basic

    PackageNamePackage.vb

    Visual C#

    PackageNamePackage.cs

For more information about VSPackages, see VSPackages. For more information about VSPackages that are created in managed code, see Managed VSPackages. For a review about menu and toolbar commands, see Introduction to Menu and Toolbar Commands.

See Also

Tasks

Walkthrough: Creating a Menu Command with the Visual Studio Integration Package Wizard

Concepts

Checklist: Creating New Project Types