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

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:

For Visual C# add-ins, add a reference to the System.Windows.Forms assembly by opening the shortcut menu for the add-in project in Solution Explorer, choosing Add, References, choosing the Add New Reference button, and selecting System.Windows.Forms.dll in the Add Reference dialog box.

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