How to: Create Solution Add-Ins

Visual Studio add-ins are deprecated in Visual Studio 2013. You should upgrade your add-ins to VSPackage extensions. For more information about upgrading, see FAQ: Converting Add-ins to VSPackage Extensions.

When you create an add-in by using the Add-In Wizard, it is automatically associated with the integrated development environment (IDE). It can be loaded when the IDE starts and it continues to run until you unload it or exit the IDE. You can alternatively associate an add-in with a solution so it becomes a Solution add-in. A Solution add-in can be useful when you want to load it only with a specific solution because of system dependencies or to minimize unnecessary usage of system resources. When Visual Studio loads a solution, it first examines the solution (.sln) file to see if it references add-ins. If so, it loads them and calls the same IDTExtensibility2 methods as a regular Visual Studio add-in.

The Add-In Wizard does not currently offer a way to indicate whether or not an add-in is a Solution add-in. However, with some minor modifications, you can make an add-in a Solution add-in. While a typical add-in stores its information in the .Addin XML file — or, in the case of an unmanaged COM add-in, in the registry — a Solution add-in stores its information in the solution's .SLN file.

Note Note

Solution add-ins must be registered by using traditional COM-based registration. Because Visual Studio 2005 add-ins use the new XML (.AddIn file) registration, you must set it to register in the Windows registry. The following procedure demonstrates how to do this.

Note Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. These procedures were developed with the General Development Settings active. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Customizing Development Settings in Visual Studio.

The following procedure describes how to create a Solution add-in.

To create a Solution add-in

  1. Create a new add-in project by using the Add-In Wizard. Select the appropriate language, and accept all other default settings.

  2. Right-click the project and select Properties.

  3. Click the Build tab and check the Register for COM interop box.

    This allows the add-in to be referenced as a COM object, which is necessary for Solution add-ins. Although the Add-In Wizard created an .AddIn XML file for the project, you do not need it for a Solution add-in, so you can delete it if you like.

  4. Since the solution add-in is a COM object, you must register it with Windows. To do this, start a Visual Studio command prompt and enter regasm /codebase SolutionAddinName.dll.

  5. Because you cannot associate an add-in with a solution file through the registry, you must use code to do it. To register the add-in with the solution file, use the Add method of the solution's AddIns collection.

    AddIns returns an AddIns collection. It is similar to AddIns except that, instead of consisting of all add-ins in Visual Studio, it consists only of the add-ins registered with the specified solution file. So, to register an add-in as a Solution add-in, use Solution.AddIns.Add.

    Here is an example in Visual Basic and Visual C#. (These lines should replace the addin variable declaration in the OnConnection method provided by the Add-In Wizard.)

    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports EnvDTE100
    Dim addin As EnvDTE.AddIn = _
    _applicationObject.Solution2.AddIns.Add("MyAddin1.Connect", "MyAddinName", "My add-in description", True)

    using EnvDTE;
    using EnvDTE80;
    using EnvDTE90;
    using EnvDTE100;
    EnvDTE.AddIn addin = 
    "MyAddinName", "My add-in description", true);