This documentation is archived and is not being maintained.

Commands2.AddNamedCommand2 Method

Creates a named command that is saved by the environment and made available the next time the environment starts, even if the Add-in is not loaded on environment startup.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Command AddNamedCommand2(
	AddIn AddInInstance,
	string Name,
	string ButtonText,
	string Tooltip,
	bool MSOButton,
	Object Bitmap,
	ref Object[] ContextUIGUIDs,
	int vsCommandStatusValue,
	int CommandStyleFlags,
	vsCommandControlType ControlType


Type: EnvDTE.AddIn
Required. The AddIn Object is adding the new command.
Type: System.String
Required. The short form of the name for your new command. AddNamedCommand2 uses the preface Addins.Progid. to create a unique name.
Type: System.String
Required. The name to use if the command is bound to a button that is displayed by name rather than by icon.
Type: System.String
Required. The text displayed when a user hovers the mouse pointer over any control bound to the new command.
Type: System.Boolean
Required. Indicates how the Bitmap parameter is interpreted.
If the value is true, Bitmap is the ID of a Microsoft Office bitmap.
If MSOButton is false, then Bitmap can be one of the following:
- A Bitmap
- An Icon
- An IPicture
- The ID of a 16x16 bitmap resource (but not an icon resource) that is provided by the add-in. Visual Studio will first look in the add-in's satellite DLL. If the resource is not found there, the add-in DLL will be searched.
Type: System.Object
Optional. The ID of a bitmap to display on the button. See MSOButton.
Type: System.Object[]
Optional. A SafeArray of GUIDs that determines which environment contexts (that is, debug mode, design mode, and so on) show the command. See vsCommandDisabledFlags.
Type: System.Int32
Optional. Determines whether the disabled state of the command is invisible or grey when you supply a ContextUIGUIDs and none are currently active.
Type: System.Int32
Optional. Determines the state of the command when you supply a ContextUIGUIDs and none of the specified contexts are currently active. This parameter should always include vsCommandStatusSupported. If it also includes vsCommandStatusEnabled, the command will be enabled..
Type: EnvDTE80.vsCommandControlType

Return Value

Type: EnvDTE.Command
The named command that was created.

For information about how to get the bitmap ID values of MSO buttons, see Listing Button Faces in the Command Bar for the Microsoft Office System.

Add-ins can later change the ButtonText name by responding to the QueryStatus method. If the text begins with #, then the rest of the string is an integer that represents a resource ID in the Add-in's registered satellite DLL.

The ContextUIGUIDs parameter and the vsCommandStatusValue parameter are used when the addin is not loaded and thus cannot respond to the QueryStatus method. If ContextUIGUIDs is empty, then the command is enabled until the addin is loaded and can respond to QueryStatus.

The addin can receive invocation notification through the IDTCommandTarget interface. A button can be added by using the OnConnection method of the IDTExtensibility2 interface.