Chapter 13: Extending Visual Studio 2010

379

Member

Purpose

OnAddInsUpdate

Add-In is either loaded or unloaded.

 

 

OnBeginShutdown

Add-In is running and VS shuts down.

 

 

OnConnection

Add-In is loaded.

OnDisconnection

Add-In is unloaded.

 

 

OnStartupComplete

VS has started up and then Add-In is loaded.

 

 

Table 13-1 The IDTExtensibility2 Interface

It’s like people from different countries trying to communicate, where they have a subject to discuss but need a common language to be able to understand each other; the common language would be the interface between the people.

The first interface to discuss is IDTExtensibility2, whose purpose is to let VS manage loading and unloading of the Add-In. Loading and unloading are important because VS loads Add-Ins when it starts and unloads Add-Ins when it shuts down. There are certain actions that you might want to take, depending on when the Add-In is loaded and what type of information you might need access to. For example, the very first time an Add-In is ever loaded, you might want to perform a special operation like configuration or asking the user if she would like to register your Add-In. Table 13-1 shows the members of IDTExtensibility2 and describes their purpose.

The second interface that Connect implements is IDTCommandTarget. When building an Add-In, you need a way for the VS IDE to execute the Add-In. For example, you will create a named command that exposes the Add-In as a menu item in the Tools menu. Whenever

a user selects the menu item, the named command will execute and run your Add-In code. IDTCommandTarget is the interface VS uses to execute your Add-In. Table 13-2 shows the members of IDTCommandTarget and describes their purpose.

Each of the methods of both the IDTExtensibility2 and IDCommandTarget interfaces are implemented by the provided Connect class. Listing 13-1 shows each of these members with full documentation comments and skeleton code. The code in Listing 13-1 is in C#, but it is very informative to take the overview of the interfaces from the previous table and then

Member

Purpose

Exec

Called by VS to execute your Add-In.

 

 

QueryStatus

Called by VS to determine if the command should be enabled,

 

invisible, or supported.

 

 

Table 13-2 The IDTCommandTarget Interface

Page 402
Image 402
Microsoft 9GD00001 manual 379, IDTExtensibility2 Interface, IDTCommandTarget Interface