HOWTO: Create command names without '.Connect' in Visual Studio add-ins

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: February 2007   Microsoft Visual Studio .NET 2003
Updated: March 2013   Microsoft Visual Studio 2005
      Microsoft Visual Studio 2008
      Microsoft Visual Studio 2010
      Microsoft Visual Studio 2012

By default, command names created by Visual Studio add-ins are of the form MyAddinNamespace.Connect.MyCommand. This becomes apparent when you try to locate a command in the dialog that is opened when you click the "Tools", "Customize..." menu, "Keyboard..." button. This article explains how to get commands of the form MyAddIn.MyCommand like the built-in ones of Visual Studio.

More Information

A full command name is composed of the full name of the class of the add-in (for example MyAddInNamespace.Connect) plus the short name of the command that is specified when calling the Commands.AddNamedCommand method. Visual Studio needs the full name of the class to create an instance of it if not already created, and then tell the instance to execute the given command name.

Visual Studio .NET 2002 and 2003 support only COM/Registry registration, while Visual Studio 2005 supports also XML registration:

  • When using COM/Registry registration, the assembly DLL of the add-in must be registered in two ways: for COM Interop and for Visual Studio inside the Windows registry. You can specify the ProgID of the Connect class that is going to be registered using the System.Runtime.InteropServices.ProgIdAttribute. The add-in wizard generates a ProgId attribute with the value ("AddInNamespace.Connect"). For example:
    <GuidAttribute("9B06A2C4-462B-43D3-9948-55FBAE5734A5"), ProgIdAttribute("MyAddin.Connect")> _
    Public Class Connect
    End Class

    To get command names without the ".Connect" part, unregister the add-in (to clean the MyAddin.Connect entries in the Windows registry), change the ProgId attribute as follows and register the add-in again:

    <GuidAttribute("9B06A2C4-462B-43D3-9948-55FBAE5734A5"), ProgIdAttribute("MyAddin")> _
    Public Class Connect
    End Class
  • When using XML registration (only available for Visual Studio 2005), you register the add-in for Visual Studio using a XML .AddIn file. No COM Interop is involved, so you can't use the ProgId attribute. In this case the only way to avoid the ".Connect" part is to proceed as follows:
    • If you are using VB.NET, in the properties window of the add-in project, clear the Root Namespace textbox to use no namespace. If you are using C#, then remove the namespace declaration enclosing the Connect class. At this point the Connect class will have no namespace.
    • Rename the "Connect" class to "MyAddIn".
    • Change the IDTCommandTarget.QueryStatus and IDTCommandTarget.Exec methods of the "Connect" class (now renamed to "MyAddIn") to use command names like "MyAddIn.MyCommand" instead of "MyAddIn.Connect.MyCommand"
    • In the two .AddIn files, change the <FullClassName> value from "MyAddIn.Connect" to "MyAddIn".

    In short, we have made a full class name without namespace and we have given the Connect class the name that we want to appear in commands. At this point the full command names of the add-in are of the form "MyAddIn.MyCommand".

Related articles

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