Export (0) Print
Expand All

How to: Compile and Run the Automation Object Model Code Examples

The code examples found in the Automation object model reference topics are designed to run in an add-in created by the Add-in Wizard. The following sections explain how to compile and run the Automation object model code examples.

To run a code sample in an add-in

  1. Create an add-in by using the Add-in Wizard.

    For more information, see How to: Create an Add-In.

  2. Add the code example to the add-in's Connect class.

  3. Call the code example procedure from the add-in's OnConnection method. If the code example requires the DTE2 object as an argument, pass in the _applicationObject member variable, which is declared in the add-in code. The following code shows the relevant portions of the Connect class from both a Visual Basic and Visual C# add-in:

    Public Sub OnConnection(ByVal application As Object, ... ) _
      Implements IDTExtensibility2.OnConnection
    
        _applicationObject = CType(application, EnvDTE80.DTE2)
            .
            .
            .
        ' Pass the _applicationObject member variable to the code 
        ' example.
        MyCodeExample(_applicationObject)
    End Sub
    ' Other methods in the Connect class.
        .
        .
        .
    
    ' This is the code example that was added to the Connect class.
    Sub MyCodeExample(ByVal dte As DTE2)
        .
        .
        .
    End Sub
    

    public void OnConnection(object application, ... , ref Array custom)
    {
        _applicationObject = (DTE2)application;
            .
            .
            .
        // Pass the _applicationObject member variable to the code 
        // example.
        MyCodeExample(_applicationObject);
    }
    
    
    // Other methods in the Connect class.
        .
        .
        .
    
    // This is the code example that was added to the Connect class.
    void MyCodeExample(DTE2 dte)
    {
        .
        .
        .
    }
    
  4. For Visual C# add-ins, add a reference to the System.Windows.Forms assembly by clicking the add-in project's name in Solution Explorer, selecting Add Reference from the Project menu, and choosing System.Windows.Forms.dll in the Add Reference dialog box.

    1. For Visual C# add-ins, insert the following code at the top of the Connect.cs file:

      using System.Windows.Forms;
      
  5. Compile the add-in by selecting Build Solution from the Build menu.

  6. Select Add-in Manager from the Tools menu.

    The Add-in Manager dialog box appears.

  7. Load the add-in by selecting the check box next to the add-in's name in the Add-in Manager dialog box, and click OK.

Show:
© 2014 Microsoft