CHAPTER 1
Microsoft’s Visual Studio is one of the most popular integrated development environments (IDE) available today. Yet as popular and powerful as Visual Studio is, there may be times when you want to add your own quirks to the tool. And fortunately, Microsoft makes it pretty easy to do just that. You can create add-ins to the various menus and toolbars to perform a variety of tasks, pretty much anything you can program. The add-in can be written in Visual Basic, C#, or C++; there are no arcane or additional languages to learn.
Visual Studio has been around in various incarnations since the late 1990s. Early Microsoft IDE products were separate for the language you were working in; Visual Basic was one tool, Visual C++ another, etc. However, with the release of Visual Studio 97, Microsoft began to bundle the various programming languages into the same IDE. Visual Studio 97 included Visual Basic, Visual C++, Visual J++, Visual FoxPro, and Visual Interdev.
When Microsoft created Visual Studio 97, it was built as an extensible core platform, making it easier for Microsoft developers to integrate new features into the IDE. They also allowed outside developers to write add-ins to enhance the product using the same extensible platform that the Visual Studio engineers worked in.
As the Visual Studio platform continued to grow, third-party developers continually wrote add-ins to integrate tools into Visual Studio. Shortly after the release of Visual Studio 2008, Microsoft created a website called the Visual Studio Gallery. New tools and enhancements are added, and as of this writing, there are more than 3,000 add-ins listed in the gallery.
The extensibility built into Visual Studio makes it an excellent environment to start and build your own “improvements” to the IDE. Getting started down that path is what this book is all about.
To build a Visual Studio add-in, you will need to create a new class that will provide implementation methods for two interfaces from the Extensibility and EnvDTE namespaces. An interface is a module containing declarations of methods and events, but with no implementation provided. This approach allows your add-in to plug and play into the Visual Studio IDE.
You will also need to generate an XML configuration file, which tells Visual Studio how to load your add-in and where your add-in’s assembly code file (DLL) can be found.
This interface from the Extensibility namespace is used to hook your add-in into the Visual Studio IDE. Although you will need to create method implementations for each of the interface events, only the OnConnection method is needed to get your add-in loaded into the IDE.
This interface from the EnvDTE namespace is used to process a request from the IDE to run your add-in. The first parameter to both methods is the command name, so your add-in code knows which (of possibly multiple) commands Visual Studio is asking about.
When implementing an add-in module, the following assemblies need to be included in the project:
There are later versions of the EnvDTE assembly, which add on additional classes, enums, and interfaces. If you choose to implement an add-in that interacts with some of the later versions of Visual Studio, you may need to include these assemblies in your project as well:
When you create an add-in module using the Add-in Wizard, EnvDTE and EnvDTE80 are typically included for you.
Visual Studio’s New Project menu includes a wizard that will generate most of the code you need to integrate your add-in into the IDE. It will also generate the XML configuration file to allow the IDE to find and load your add-in program. In the next chapter, we will use this wizard to create the famous “Hello World” programming example.