Walkthrough: Adding a Menu to the Visual Studio Menu Bar (C#)
This walkthrough shows how to add a menu to the menu bar of the Visual Studio integrated development environment (IDE). The IDE menu bar contains menu categories such as File, Edit, View, Window, and Help.
By completing this walkthrough, you can create a menu named TestMenu that contains one command. If the command is unavailable, the menu does not appear.
Menus are declared in the .vsct file of the project. For more information about menus and .vsct files, see Commands, Menus, and Toolbars.
The Visual Studio Package project template is available in three locations in the New Project dialog box:
Under Visual Basic Extensibility. The default language of the project is Visual Basic.
Under C# Extensibility. The default language of the project is C#.
Under Other Project Types Extensibility. The default language of the project is C++.
To create the TopLevelMenu VSPackage
Create a VSPackage named TopLevelMenu. For more information, see Walkthrough: Creating a Menu Command By Using the Visual Studio Package Template.
In the Visual Studio Package template, set the programming language to Visual C# or Visual Basic, select Menu Command, set the command name to Test Command, and set command ID to cmdidTestCommand.
To create a menu
In Solution Explorer, open TopLevelMenu.vsct.
At the end of the file, there is a Symbols node that contains several GuidSymbol nodes. In the node named "guidTopLevelMenuCmdSet", add a new symbol, as follows:
Create an empty Menus node in the Commands node, just before Groups.
In the Menus node, create the following Menu node to define the menu registered in step 2:
The guid and id values of the menu specify the command set and the specific menu in the command set.
The guid and id values of the parent position the menu on the section of the Visual Studio menu bar that contains the Tools and Add-ins menus.
The value of the CommandName string specifies that the text should appear in the menu item.
Change the GUID/ID pair of the parent of the generated Group node so that it is the same as that of the menu you created, as follows:
This makes the group part of the new menu.
Find the Buttons section. Notice that the Visual Studio Package template has generated a Button element that has its parent set to MyMenuGroup. As a result, this command will appear on your menu.
To build and test the VSPackage
Press F5 to open an instance of the Visual Studio experimental environment in debug mode.
The menu bar in the Visual Studio experimental environment should contain a TestMenu menu that is positioned just before the Analyze menu.
On the TestMenu menu, click Test Command.
A message box should appear and display the message "Inside Company.TopLevelMenu.TopLevelMenuPackage.MenuItemCallback()". This indicates that the new command works.