Microsoft 9GD00001 Computer Accessories User Manual


 
378 Microsoft Visual Studio 2010: A Beginner’s Guide
methods that are numbered, such as the IDTExtensibility and IDTExtensibility2, where
IDTExtensibility2 is a more recent version with additional members. I’ll explain what the
IDTExtensibility2 interface does later, but what you should get out of this example is how
each version of the EnvDTE assemblies manages newer versions of code. This scheme
promotes the addition of new functionality for each version of VS without sacrificing
backward compatibility.
The Connect class contains the code that interacts with VS to make an Add-In work.
Remember, this is a VS project, just like all of the other projects you can create. You’re
free to add classes containing your functionality and have code in Connect call your
classes, organize code into folders, or add a class library to the solution and call code in
the class library. The next section discusses internals of Connect in detail.
The other items of note in this project are the files with the *.AddIn extensions.
These are the deployment files. There was a time when you were required to go into the
Windows registry to configure an Add-In, but not anymore. The Add-In configuration is
done in the *.AddIn files, which contains XML. In a later section of this chapter, you’ll
see the internals of the *.AddIn file and learn how to manipulate this file for deployment.
Additionally, one of the *.AddIn files has a shortcut arrow, which is a special shortcut
to a file used for debugging. If you look at the properties for this shortcut file, you’ll
notice that it points at your Documents\Visual Studio 2010\Addins\folder, which is a
deployment location. Whenever you debug this application, VS uses the debugging
*.AddIn file to load the Add-In in a new copy of VS. You would manipulate the Add-In in
the new copy of VS, and your current copy of VS, in debugging mode, can hit breakpoints
and debug the Add-In.
Now that you know the key elements of an Add-In project, the next section drills down
into the Connect class and describes the members that interact with VS to run an Add-In.
Drilling into the Connect Class
The Connect class implements two interfaces, IDTExtensibility2 and IDTCommandTarget,
and contains several members. Before examining the code, you’ll learn about the interfaces,
their members, and purpose.
The purpose of the interfaces (IDTExtensibility2 and IDTCommandTarget) is to help
manage the lifetime of the Add-In. VS understands these interfaces, but it doesn’t know
anything about the code you write. Therefore, you have to bridge the gap between your
code and what VS needs to make an Add-In work. To do this, you use a class (Connect) that
implements the interfaces (IDTExtensibility2 and IDTCommandTarget). Then you place
your code into methods, members of Connect, that implement (match) the interfaces. When
VS communicates with the interfaces, your code (implementing the interface) executes.