We recommend using Visual Studio 2017

Walkthrough: Extending Managed VSPackages By Using Automation


This walkthrough illustrates how to use automation to create a managed VSPackage that manipulates the Visual Studio integrated development environment (IDE). You create a sample managed VSPackage and then use automation methods in the resulting VSPackage to display Visual Studio properties in the Output window.


To follow this walkthrough, you must install the Visual Studio SDK. For more information, see Visual Studio SDK.

The Visual Studio Package project template can be found in three different locations in the New Project dialog:

  1. Under Visual Basic Extensibility. The default language of the project is Visual Basic.

  2. Under C# Extensibility. The default language of the project is C#.

  3. Under Other Project Types Extensibility. The default language of the project is C++.

To create a managed VSPackage

  1. Create a Visual Studio Package project named Auto.

    For more information about how to create a managed VSPackage, see Walkthrough: Creating a Menu Command By Using the Visual Studio Package Template.

  2. On the Select a Programming Language page, set the language to Visual C#.

  3. Keep the default values in the Basic VSPackage Information page.

  4. On the Select VSPackage Options page, select the Menu Command check box.

  5. On the Command Options page, change the Command Name to Auto.

  6. Click the Finish button.

    The template generates a managed project named Auto.

  7. Build the solution and verify that it compiles without errors.

To call the Automation model

  1. In Solution Explorer, right-click the Auto project node and then click Add, Reference.

  2. On the .NET tab of the Reference dialog box, double-click EnvDTE.

    This adds a reference to the EnvDTE automation namespace.

  3. In the AutoPackage file, add the following namespace reference.

    using EnvDTE;
  4. In the AutoPackage file, replace the body of the MenuItemCallback method with the following lines:

    private void MenuItemCallback(object sender, EventArgs e)
        DTE dte;
        dte = (DTE)GetService(typeof(DTE));
        string myString =
          "Name is " + dte.Name + "\rVersion is " + dte.Version;
        Windows windows = dte.Windows;
        Window window =
        window.Visible = true;
        OutputWindow outputWindow = (OutputWindow)window.Object;
        OutputWindowPane outputWindowPane =

This code calls GetService to obtain a DTE automation object that represents the Visual Studio IDE. The automation code in MenuItemCallback creates a new pane in the Output window named Test. The Visual Studio name and version is then written to the new Output pane.

  1. Build and start the Auto project in debug mode by pressing F5.

    This starts the Visual Studio experimental build (Visual Studio Exp).


    Both versions of Visual Studio are open at this point.

  2. In Visual Studio Exp, on the Tools menu, click Auto.

    A new pane named Test opens in the Output window and displays the following:

    Name is Microsoft Visual Studio
    Version is x.xx

    Where x.xx is the latest Visual Studio version number.

    For more information about automation samples, see Automation Samples for Visual Studio.