52.3. The Anatomy of an Add-In

The Add-in Wizard generates a solution with a single project in it. This project contains a Connect.cs file, which is the main implementation file for the add-in, as well as two files with the .AddIn extension and a resource file for command bar resources.

The main parts of the add-in are the Connect.cs file and an .AddIn file. In earlier versions of Visual Studio you had to register the COM component by hand for an add-in on the machine, so deployment was harder than what you see in Visual Studio 2005 and 2008, but with the introduction of .AddIn files this process has been made simpler. .AddIn files are XML files that act as configuration files for add-ins. You'll read more about them in the next section, but for now let's focus on the add-in anatomy and the Connect.cs file.

First, look at the generated code for the Connect class:

using System; using Extensibility; using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio.CommandBars; using System.Resources; using System.Reflection; using System.Globalization; namespace Chapter52 { public class Connect : IDTExtensibility2, IDTCommandTarget { public Connect() { } public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_UISetup) { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; ...

Get Professional Visual Studio® 2008 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.