Condividi tramite


How to: Add References to Automation Namespaces

In Visual Studio 2013, add-ins are deprecated. We recommend that you upgrade your add-ins to VSPackage extensions. For more information about how to upgrade, see FAQ: Converting Add-ins to VSPackage Extensions.

When you add a reference to EnvDTE, EnvDTE80, EnvDTE90, or EnvDTE100, you have the choice of using a .NET assembly or a COM library version. The one you should choose depends upon your project.

If you are maintaining an older application or add-in, you might need to use the COM version of EnvDTE, EnvDTE80, EnvDTE90, or EnvDTE100. If you are creating a new managed application or add-in, though, you will most likely want to use the .NET assembly version.

When you use the Add-in Wizard to create an add-in in any programming language or when you create a macro, the process adds references to the EnvDTE, EnvDTE90, Env90, and Env100 assemblies, and in the file containing the Connect class it adds using (in Visual Basic, imports) directives to the EnvDTE and EnvDTE80 namespaces.

To access the automation objects outside of macros or add-ins created with the Add-in Wizard, however, you must manually add the assembly references and using (in Visual Basic, imports) directives. When you add an assembly reference manually, you must also set the Embed Interop Types property of the assembly to false. To do this, follow these steps:

  1. Add the assembly reference. In Solution Explorer, open the shortcut menu for the project, choose Add, References, and then choose the Add New Reference button. On the .NET tab, select the assembly, and then choose the OK button. In a C# project, you will see the name of the assembly under the References node in Solution Explorer. In a Visual Basic project, you will see the name of the assembly in the project properties. Right-click the project in Solution Explorer, and select Properties. The properties pages will appear. Select the References page in the left pane.

  2. Select the assembly reference, and in the Properties window set the Embed Interop Types property of the assembly to false.

After you add references to the namespaces, you will most likely want to program against the DTE and DTE2 objects. For more information, see How to: Get References to the DTE and DTE2 Objects.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings in Visual Studio.

To manually add references to the EnvDTE namespaces in Visual Basic or Visual C#

  1. In Solution Explorer, open the shortcut menu for the project, choose Add, References, and then choose the Add New Reference button.

  2. In the Add Reference dialog box, on the tab for the kind of component you want—for example, .NET or COM—select EnvDTE, EnvDTE80, EnvDTE90, and EnvDTE100.

  3. Choose the OK button to add the two new references to the project.

  4. To enable Intellisense for the new assemblies in the code editor, at the top of your project's module or class, add one of the following:

    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports EnvDTE100
    
    using EnvDTE;
    using EnvDTE80;
    using EnvDTE90;
    using EnvDTE100;
    

To manually add references to the EnvDTE namespaces in Managed Visual C++

  1. In Solution Explorer, open the shortcut menu for the project, choose Add, References, and then choose the Add New Reference button.

  2. On the .NET tab, select EnvDTE, EnvDTE80, and EnvDTE90 and then choose the Add button.

  3. Choose OK to add the new references to the project.

  4. To enable IntelliSense for the new assemblies in the code editor, at the top of your main project file, add the following:

    // Visual C++
    #using <envdte.dll>
    #using <envdte80.dll>
    #using <envdte90.dll>
    #using <envdte100.dll>
    

To add references to EnvDTE and EnvDTE80 namespaces to Non-Managed (ATL) Visual C++

  • In an appropriate header or source file, add the following:

    #pragma warning( disable : 4278 )
    #pragma warning( disable : 4146 )
    //The following #import imports EnvDTE based on its LIBID.
    #import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("8.0") 
    lcid("0") raw_interfaces_only named_guids
    //The following #import imports EnvDTE80 based on its LIBID.
    #import "libid:1A31287A-4D7D-413e-8E32-3B374931BD89" version("8.0") 
    lcid("0") raw_interfaces_only named_guids
    //The following #import imports EnvDTE90 based on its LIBID.
    #import "libid: 2ce2370e-d744-4936-a090-3fffe667b0e1" version("9.0") 
    lcid("0") raw_interfaces_only named_guids
    //The following #import imports EnvDTE100 based on its LIBID.
    #import "libid: 26ad1324-4b7c-44bc-84f8-b86aed45729f" version("10.0") 
    lcid("0") raw_interfaces_only named_guids
    #pragma warning( default : 4146 )
    #pragma warning( default : 4278 )
    

See Also

Tasks

How to: Control Add-Ins By Using the Add-In Manager

Walkthrough: Creating a Wizard

Concepts

Add-In Registration

Automation Object Model Chart

Other Resources

Creating Add-ins and Wizards