Adding a Menu to the Visual Studio Menu Bar
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.
Before adding a new menu to the Visual Studio menu bar, consider whether your commands should be placed within an existing menu. For more information about command placement, see Menus and Commands for Visual Studio.
Menus are declared in the .vsct file of the project. For more information about menus and .vsct files, see Commands, Menus, and Toolbars.
By completing this walkthrough, you can create a menu named TestMenu that contains one command.
Starting in Visual Studio 2015, you do not install the Visual Studio SDK from the download center. It is included as an optional feature in Visual Studio setup. You can also install the VS SDK later on. For more information, see Installing the Visual Studio SDK.
Create a VSIX project named
TopLevelMenu. You can find the VSIX project template in the New Project dialog under Visual C# / Extensibility. For more information, see Creating an Extension with a Menu Command.
When the project opens, add a custom command item template named TestCommand. In the Solution Explorer, right-click the project node and select Add / New Item. In the Add New Item dialog, go to Visual C# / Extensibility and select Custom Command. In the Name field at the bottom of the window, change the command file name to TestCommand.cs.
In Solution Explorer, open TestCommandPackage.vsct.
At the end of the file, there is a <Symbols> node that contains several <GuidSymbol> nodes. In the node named guidTestCommandPackageCmdSet, add a new symbol, as follows:
Create an empty <Menus> node in the <Commands> node, just before <Groups>. In the <Menus> node, add a <Menu> node , as follows:
<Menus> <Menu guid="guidTestCommandPackageCmdSet" id="TopLevelMenu" priority="0x700" type="Menu"> <Parent guid="guidSHLMainMenu" id="IDG_VS_MM_TOOLSADDINS" /> <Strings> <ButtonText>TestMenu</ButtonText> <CommandName>TestMenu</CommandName> </Strings> </Menu> </Menus>
idvalues of the menu specify the command set and the specific menu in the command set.
idvalues 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
CommandNamestring specifies that the text should appear in the menu item.
In the <Groups> section, find the <Group> and change the <Parent> element to point to the menu we just added:
<Groups> <Group guid="guidTestCommandPackageCmdSet" id="MyMenuGroup" priority="0x0600"> <Parent guid="guidTestCommandPackageCmdSet" id="TopLevelMenu"/> </Group> </Groups>
This makes the group part of the new menu.
Buttonssection. Notice that the Visual Studio Package template has generated a
Buttonelement that has its parent set to
MyMenuGroup. As a result, this command will appear on your menu.
Build the project and start debugging. An instance of the experimental instance should appear.
The menu bar in the experimental instance should contain a TestMenu menu.
On the TestMenu menu, click Invoke Test Command.
A message box should appear and display the message "TestCommand Package Inside TopLevelMenu.TestCommand.MenuItemCallback()". This indicates that the new command works.