Logo
INFO: How a Visual Studio package command is named.

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2010
Date: July 2014   Microsoft Visual Studio 2012
      Microsoft Visual Studio 2013
Introduction

In Visual Studio, apart from a Guid/Id identity, a command has a name, normally composed of two terms separated by a period such as "File.Exit", not to be confused with the text (caption) of user interface items (toolbar buttons and menu items) bound to it. This article explains how to a name is composed.

More Information

Despite the name, the <CommandName> property that you set in the .vsct file is not appropriate to set the name of a command. In fact, it should be removed, because if present, its value is used in the Tools > Customize window of Visual Studio, while the command text (<ButtonText>) is actually what you would like to appear in that dialog.

The first term of the name of a command is obtained as follows:

  • If the command is placed on a main menu (such as "Tools", or your own main menu), it is obtained from the text of the main menu item, removing spaces, ellipses and ampersands, no matter which other properties (<CommandName>, <LocCanonicalName>, <CanonicalName>) you set in the <Strings> section of the .vsct file.
  • If the command is placed on a submenu (such as "View" > "Other Windows"), it is obtained from the text of the main menu item which the submenu belongs to, removing spaces, ellipses and ampersands, no matter which other properties (<CommandName>, <LocCanonicalName>, <CanonicalName>) you set in the <Strings> section of the .vsct file.
  • If the command is placed only on a context menu of Visual Studio, it is obtained from the name assigned by Visual Studio to that context menu, for example "EditorContextMenus.CodeWindow" for the context menu of the code window.
  • If the command is placed only on a toolbar, or placed nowhere (see the article HOWTO: Create a command without user interface items from a Visual Studio package), then the first term is empty. In this case you can use the second term to specify the full name of the command (with a period separator, such as "MyPackage.MyCommand").

The second term of the name of a command is obtained as follows:

  • If present, from the <LocCanonicalName> value of the command in the <Strings> section.
  • If that value is missing, from the <ButtonText> value of the command in the <Strings> section, removing spaces, ellipses and ampersands.

That means that unless you place your commands only on toolbars, you don't have full control to specify the full name of the commands of your package. If you place the commands on a main menu created by your package, the text of that main menu will determine the first term of the name of the commands.



Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)