Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
This document shows how to author a .vsct file to add menu items, toolbars, and other user interface (UI) elements to the Visual Studio integrated development environment (IDE). Use these steps when you add UI elements to a Visual Studio Package (VSPackage) that does not already have a .vsct file.
For new projects, we recommend that you use the Visual Studio Package template because it generates a .vsct file that, depending on your selections, already has the required elements for a menu command, a tool window, or a custom editor. You can modify this .vsct file to meet the requirements of your VSPackage. For more information about how to modify a .vsct file, see the examples in Extending Menus and Commands.
Authoring the File
Author a .vsct file in these phases: Create the structure for files and resources, declare the UI elements, put the UI elements in the IDE, and add any specialized behaviors.
File Structure
The basic structure of a .vsct file is a CommandTable root element that contains a Commands element and a Symbols element.
To create the file structure
- Add a .vsct file to your project by following the steps in How to: Create a .Vsct File. 
- Add the required namespaces to the - CommandTableelement, as shown in the following example.- <CommandTable xmlns="https://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
- In the - CommandTableelement, add a- Commandselement to host all of your custom menus, toolbars, command groups, and commands. So that your custom UI elements can load, the- Commandselement must have its- Packageattribute set to the name of the package.- After the - Commandselement, add a- Symbolselement to define the GUIDs for the package, and the names and command IDs for your UI elements.
Including Visual Studio Resources
Use the Extern element to access the files that define Visual Studio commands and the menus that are required to put your UI elements in the IDE. If you will use commands defined outside your package, use the UsedCommands element to inform Visual Studio.
To include Visual Studio resources
- At the top of the - CommandTableelement, add one- Externelement for each external file to be referenced, and set the- hrefattribute to the name of the file. You can reference the following header files to access Visual Studio resources:- Stdidcmd.h, defines IDs for all commands exposed by Visual Studio. 
- Vsshlids.h, contains command IDs for Visual Studio menus. 
 
- If your package calls any commands that are defined by Visual Studio or by other packages, add a - UsedCommandselement after the- Commandselement. Populate this element with a UsedCommand element for each command you call that is not part of your package. Set the- guidand- idattributes of the- UsedCommandelements to the GUID and ID values of the commands to call. For more information about how to find the GUIDs and IDs of Visual Studio commands, see GUIDs and IDs of Visual Studio Commands. To call commands from other packages, use the GUID and the ID of the command as defined in the .vsct file for those packages.
Declaring UI Elements
Declare all new UI elements in the Symbols section of the .vsct file.
To declare UI elements
- In the - Symbolselement, add three GuidSymbol elements. Each- GuidSymbolelement has a- nameattribute and a- valueattribute. Set the- nameattribute so that it reflects the purpose of the element. The- valueattribute takes a GUID. (To generate a GUID, on the Tools menu, click Create GUID, and then select Registry Format.)- The first - GuidSymbolelement represents your package, and typically has no children. The second- GuidSymbolelement represents the command set, and will contain all of the symbols that define your menus, groups, and commands. The third- GuidSymbolelement represents your image store and contains symbols for all of the icons for your commands. If you have no commands that use icons, you can omit the third- GuidSymbolelement.
- In the - GuidSymbolelement that represents your command set, add one or more IDSymbol elements. Each of these represent a menu, toolbar, group, or command you are adding to the UI.- For each - IDSymbolelement, set the- nameattribute to the name you will use to refer to the corresponding menu, group, or command, and then set the- valueelement to a hexadecimal number that will represent its command id. No two- IDSymbolelements that have the same parent can have the same value.
- If any of your UI elements require icons, add an - IDSymbolelement for each icon to the- GuidSymbolelement that represents your image store.
Putting UI Elements in the IDE
The Menus element, Groups element, and Buttons element contain the definitions for all of the menus, groups, and commands that are defined in your package. Put these menus, groups, and commands in the IDE either by using a Parent element, which is part of the UI element definition, or by using a CommandPlacement element that is defined elsewhere.
Each Menu, Group, and Button element has a guid attribute and an id attribute. Always set the guid attribute to match the name of the GuidSymbol element that represents your command set, and set the id attribute to the name of the IDSymbol element that represents your menu, group, or command in the Symbols section.
To define UI elements
- If you are defining any new menus, submenus, shortcut menus, or toolbars, add a - Menuselement to the- Commandselement. Then, for each menu to be created, add a Menu element to the- Menuselement.- Set the - guidand- idattributes of the- Menuelement, and then set the- typeattribute to the kind of menu you want. You may also set the- priorityattribute to establish the relative position of the menu in the parent group.- Note - The - priorityattribute does not apply to toolbars and context menus.
- All commands in the Visual Studio IDE must be hosted by command groups, which are the direct children of menus and toolbars. If you are adding new menus or toolbars to the IDE, these must contain new command groups. You may also add command groups to existing menus and toolbars so that you can visually group your commands. - When you add new command groups, you must first create a - Groupselement, and then add to it a Group element for each command group.- Set the - guidand- idattributes of each- Groupelement, and then set the- priorityattribute to establish the relative position of the group on the parent menu. For more information, see Creating Reusable Groups of Buttons.
- If you are adding new commands to the IDE, add a - Buttonselement to the- Commandselement. Then, for each command, add a Button element to the- Buttonselement.- Set the - guidand- idattributes of each- Buttonelement, and then set the- typeattribute to the kind of button you want. You may also set the- priorityattribute to establish the relative position of the command in the parent group.- Note - Use - type="button"for standard menu commands and buttons on toolbars.
- In the - Buttonelement, add a Strings element that contains a ButtonText element and a CommandName element. The- ButtonTextelement provides the text label for a menu item, or the tooltip for a toolbar button. The- CommandNameelement provides the name of the command to use in the command well.
- If your command will have an icon, create an Icon element in the - Buttonelement, and set its- guidand- idattributes to the- Bitmapelement for the icon.- Note - Toolbar buttons must have icons. - For more information, see MenuCommands Vs. OleMenuCommands. 
 
- If any of your commands require icons, add a Bitmaps element to the - Commandselement. Then, for each icon, add a Bitmap element to the- Bitmapselement. This is where you specify the location of the bitmap resource. For more information, see Adding Icons to Menu Commands.- You can rely on the parenting structure to correctly place most menus, groups, and commands. For very large command sets, or when a menu, group, or command must appear in multiple places, we recommend that you specify command placement. 
To rely on parenting to place UI elements in the IDE
- For typical parenting, create a - Parentelement in each- Menu,- Group, and- Commandelement that is defined in your package.- The target of the - Parentelement is the menu or group that will contain the menu, group, or command.- Set the - guidattribute to the name of the- GuidSymbolelement that defines the command set. If the target element is not part of your package, use the guid for that command set, as defined in the corresponding .vsct file.
- Set the - idattribute to match the- idattribute of the target menu or group. For a listing of the menus and groups that are exposed by Visual Studio, see GUIDs and IDs of Visual Studio Menus or GUIDs and IDs of Visual Studio Toolbars.
 - If you have a large number of UI elements to place in the IDE, or if you have elements that should appear in multiple places, define their placements in the CommandPlacements element, as shown in the following steps. 
To use command placement to place UI elements in the IDE
- After the - Commandselement, add a- CommandPlacementselement.
- In the - CommandPlacementselement, add a- CommandPlacementelement for each menu, group, or command to place.- Each - CommandPlacementelement or- Parentelement places one menu, group, or command in one IDE location. A UI element can only have one parent, but it can have multiple command placements. To place a UI element in multiple locations, add a- CommandPlacementelement for each location.
- Set the - guidand- idattributes of each- CommandPlacementelement to the hosting menu or group, just as you would for a- Parentelement. You can also set the- priorityattribute to establish the relative position of the UI element.- You can mix placement by parenting and command placement. However, for very large command sets, we recommend that you use only command placement. 
Adding Specialized Behaviors
You can use CommandFlag elements to modify the behavior of menus and commands, for example, to change their appearance and visibility. You can also affect when a command is visible by using VisibilityConstraints, or add keyboard shortcuts by using KeyBindings. Certain kinds of menus and commands already have specialized behaviors built in.
To add specialized behaviors
- To make a UI element visible only in certain UI contexts, for example, when a solution is loaded, use visibility constraints. - After the - Commandselement, add a- VisibilityConstraintselement.
- For each UI item to constrain, add a VisibilityItem element. 
- For each - VisibilityItemelement, set the- guidand- idattributes to the menu, group, or command, and then set the- contextattribute to the UI context you want, as defined in the UIContextGuids80 class. For more information, see VisibilityItem Element.
 
- To set the visibility or availability of a UI item in code, use one or more of the following command flags: - DefaultDisabled 
- DefaultInvisible 
- DynamicItemStart 
- DynamicVisibility 
- NoShowOnMenuController 
- NotInTBList - For more information, see Command Flag Element. 
 
- To change how an element appears, or change its appearance dynamically, use one or more of the following command flags: - AlwaysCreate 
- CommandWellOnly 
- DefaultDocked 
- DontCache 
- DynamicItemStart 
- FixMenuController 
- IconAndText 
- Pict 
- StretchHorizontally 
- TextMenuUseButton 
- TextChanges 
- TextOnly - For more information, see Command Flag Element. 
 
- To change how an element reacts when it receives commands, use one or more of the following command flags: - AllowParams 
- CaseSensitive 
- CommandWellOnly 
- FilterKeys 
- NoAutoComplete 
- NoButtonCustomize 
- NoKeyCustomize 
- NoToolbarClose 
- PostExec 
- RouteToDocs 
- TextIsAnchorCommand - For more information, see Command Flag Element. 
 
- To attach a menu-dependent keyboard shortcut to a menu or an item on a menu, add an ampersand character ('&') in the - ButtonTextelement for the menu or menu item. The character that follows the ampersand is the active keyboard shortcut when the parent menu is open.
- To attach a menu-independent keyboard shortcut to a command, use KeyBindings. For more information, see KeyBinding Element. 
- To localize menu text, use the - LocCanonicalNameelement. For more information, see Strings Element.- Some menu and button types include specialized behaviors. The following table describes some specialized menu and button types. For other types, see the - typesattribute descriptions in Menu Element, Button Element, and Combo Element.- Combo box 
 A combo box is a drop-down list that can be used on a toolbar. To add combo boxes to the UI, create a Combos element in the- Commandselement. Then add to the- Comboselement a- Comboelement for each combo box to add.- Comboelements have the same attributes and children as- Buttonelements and also have- DefaultWidthand- idCommandListattributes. The- DefaultWidthattribute sets the width in pixels, and the- idCommandListattribute points to a command ID that is used to populate the combo box. For more information, see the- Comboelement documentation.- MenuController 
 A menu controller is a button that has an arrow next to it. Clicking the arrow opens a list. To add a menu controller to the UI, create a- Menuelement and set its- typeattribute to MenuController or MenuControllerLatched, depending on the behavior you want. To populate a menu controller, set it as the parent of a- Groupelement. The menu controller will display all children of that group on its drop-down list.
See Also
Extending Menus and Commands
Visual Studio Command Table (.Vsct) Files
VSCT XML Schema Reference