Walkthrough: Creating a Menu Command VSPackage
This walkthrough demonstrates how to generate a VSPackage that includes a menu command on the Tools menu. This walkthrough hows how to do the following tasks by using the Visual Studio Package Wizard:
Create a VSPackage in either Visual C++ or a managed VSPackage in Visual C#.
Add a menu control to the VSPackage.
Build the VSPackage generated by the wizard.
When you finish, you will have a basic VSPackage that is correctly registered in the Visual Studio Exp environment and a new menu command at the top of the Tools menu.
Creating a VSPackage
To start the Visual Studio Integration Package Wizard
On the File menu, point to New, and then click New Project.
In the New Project dialog box:
Click Project Types, point to Other Project Types, and then select Extensibility.
Click Visual Studio Integration Package in the Templates pane. Type in the name for your VSPackage in the Name text box, and the file path in the Location text box.
Click OK to start the Visual Studio Package Wizard.
Read the information on the Welcome to the Visual Studio Package Wizard page, and then click Next.
In the Select a Programming Language page, you can choose to create your VSPackage in either Visual C++ or Visual C#.
If you select Visual C#, 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.
In the Basic VSPackage Information page, type the name of your company, your VSPackage name and version, and detailed information about your VSPackage in the corresponding text boxes. Select the minimum Visual Studio edition you want your VSPackage to support from the Minimum Visual Studio Edition dropdown menu.
The VSPackage name displays in the Visual Studio Splash Screen, the Help About dialog box, and the VSPackage registry. The version information displays in the VSPackage registry and the Help About dialog box.
The name of your company is used if you later decide to obtain a VSPackage Load Key for your VSPackage. For more information about VSPackage Load Keys, see VSPackage Load Keys.
The icon for your VSPackage displays in the Splash Screen and the Help About dialog box. To select an icon that differs from the default icon (displayed on the wizard page) click Change Icon. The resulting Change Icon dialog box displays the default icon. Click Browse to select an icon from another location on your computer.
In the Select VSPackage Options page, select Menu Command.
In the Command Options page enter the name and command ID for your menu command. Click Finish to generate your VSPackage.
Testing your VSPackage
The VSPackage generated by the Visual Studio Integration Package Wizard will be correctly registered to run in the Visual Studio Exp environment. When you build your VSPackage, the build process merges the UI elements and registers the generated VSPackage with Visual Studio.
To start an instance of Visual Studio
At the Visual Studio command prompt, type devenv /rootsuffix exp.
Alternately, select Start on the Debug menu, or click the Run button in the toolbar to start the experimental interactive development environment (IDE).
If your VSPackage is generated in Visual C#, 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.
In the experimental version of Visual Studio, your menu command, together with the icon you chose, displays on the Tools menu. If you click the menu command, a message box appears with the text:
"Executing the command" if your VSPackage was generated in Visual C++.
"Inside <Company>.<Project name>.<Project name>.MenuItemCallback()" if your VSPackage was generated in Visual C#.
You must provide the code — in VsPkg.cpp for a VSPackage created in Visual C++, or in VsPkg.cs for a VSPackage created in Visual C# — to extend your menu command.
For more information about VSPackages, see VSPackages. For more information about VSPackages created in managed code, see Managed VSPackages. For a review on menu and toolbar commands, see Introduction to Menu and Toolbar Commands
See Also
Concepts
Visual Studio Integration Samples