I am a fan of Visual Studio. Several times I flirted with the idea to create a VS packages for some development utilities. I always wanted to convince my colleagues to implement their utilities as VS packages. However, when they asked me how to start, I always pointed to the VS SDK and its documentation. My colleagues most common reactions can be best described by the following sentences:
“I don’t have time to go through hundreds of pages...”
“I don’t know COM, and do not want to deal with that stuff; I want my .NET classes...”
“I read the first fifty pages but no idea how to start quickly...”
“I saw the SDK samples but it seems difficult to create my own package...”
I do not think that the only problem is the attitude of my colleagues. They could learn .NET, WinForms, ASP.NET, WCF, etc. I know, they are able to learn VSX (VS SDK). What they told me is they found it difficult and time-consuming.
As an MVP I decided to change the world a bit around the Visual Studio 2008 SDK and VS packages. I am one of those guys who feel themselves at home in .NET programming and in using Visual Studio, but who are not so self-confident when it is about VS SDK. I decided to learn many aspects of the VS extensibility and publish my way of learning it. My aim is to give starting points to others helping to understand and use VSX while explaining the most important things to demystify the whole VSX programming. I am focusing on developers who are new to VSX, and so the code name of my project is “LearnVSXNow”.
It is a good feeling to know that I am not alone. In November I met with the Visual Studio Extensibility Team at TechEd 2007 in Barcelona and after having discussions with them I got convinced those guys are making a great job. I read the CoDe magazine dedicated to VSX and I know a few book is to be published about VSX in a few month.
First steps
To use Visual Studio 2008 SDK in practice you need to install both Visual Studio 2008 and Visual Studio 2008 SDK. As an MSDN subscriber you can download Visual Studio 2008 Professional and install to your computer (or you can get it on many other official ways). Visit the Visual Studio Extensibility Developer Center at http://msdn.com/vsx to find and download Visual Studio 2008 SDK, then install it.
How to integrate functionality into the Visual Studio IDE?
Visual Studio Extensibility is a common name for countless ways of adding functionality to Visual Studio (and even for Team Foundation Server) to extend it with features helping a development project team to perform better. We create a component extending Visual Studio in order to add some value to our everyday job. Visual Studio would not be a great Microsoft product if there were only one way to extend it. We have many options. From programming aspect, the basic options are macros, add-ins and Visual Studio packages.
Macros
We are familiar with using macros in Office products. In a very similar way we can extend Visual Studio 2008 with macros. This is the easiest way to extend Visual Studio — we even do not need VS SDK. Visual Studio offers us functions to record macros and so we can automate repetitive tasks in a few minutes. Macros access the Visual Studio 2008 object model and easily combine VS commands with useful automation property values to get the desired behavior.
To become a professional macro developer you need to know the object model behind the macros and a few dozen of patterns about using those objects. Visual Studio 2008 comes with a few macro samples to get a flying start. The best way to learn macro programming is to record macros and view recording results. You can extend this knowledge by borrowing coding patters from the samples.
Although macros are great for task automation, they are not the right tools to create totally new functionality. From a simplified architectural point of view, macros use the automation interface of the Visual Studio IDE and they do not really integrate with (or into) the IDE. When using macros, you should be aware of the fact that anyone can see the source code of your macro.
In LearnVSXNow I do not intend to treat macros and macro programming.
Visual Studio Add-ins
Add-ins are much more powerful to develop Visual Studio extensions, since you can access the Visual Studio 2008 object model and add new user interface elements to the IDE just like tool windows, option pages, menu and toolbar commands, etc. The functions you add with an add-in look like if they were the part of the IDE. Your add-ins can access services provided by not only the IDE itself but also by other add-ins or packages.
Branding is also available, you can display add-in product information on the Visual Studio splash screen or in the About dialog.
If you write a macro actually anyone can see the code you have written. An add-in is a compiled (.NET) binary, so you can use the same intellectual property guarding techniques as for any other .NET binaries.
To deploy an add-in you simply create a setup project that produces an .msi file. Running this .msi will do all the setup and registration tasks required for your add-in and you can immediately start to use it with Visual Studio.
For simple utilities an add-in is the easiest way to start with. In LearnVSXNow I will not focus on developing add-ins, but the techniques used for package development — especially using the object model of VS IDE — can be very useful.
Visual Studio Packages
There is no doubt developing VS Packages is the most powerful way to add functionality to Visual Studio. The clear evidence for this is the fact that the whole Visual Studio functionality is build from packages integrated into the shell. All the languages, editors, the debugger, the project system and many more components are packages.
From developers point of view it actually means that adding a new package to VS is just like adding core functionality to the VS IDE as if it were developed by Microsoft. The IDE does not make any distinction between Microsoft-created and third-party components; you see all packages as part of VS IDE.
Packages are binaries developed with your preferred language (C#, VB.NET or C++), so from intellectual property guarding aspect they can be as safe as other .NET binaries.
For deployment point of view, installing packages is a more complex task than setting up add-ins. Registration of packages affects a broader part of the Visual Studio registry entries and is helped by a utility called regpkg.exe. Visual Studio checks if it can trust in a package by a signing mechanism that uses a so-called Package Load Key. This PLK can be obtained from Microsoft and is a kind of digital hash for your package. When your package is installed into a production environment, its PLK is verified.
In LearnVSXNow I definitely focus on developing Visual Studio packages.
How to start?
Comparing the three basic ways of integrating functionality (or in the case of add-ins and packages it is better to say components) into VS IDE, it is clear the macros only “scratch” the integration surface. Add-ins and packages allow developers to take a deep dive under this surface and create premium functionality not available through macros. So, in my posts I am going to treat VS package programming. Those who want to develop “only” add-ins these posts also can be useful.
Microsoft says: “to successfully develop a VSPackage you must learn the interop assemblies”. This is a weird task and takes a lot of time. This is the area where I want to help you. I would not say you must learn the interop assemblies, I rather say you must understand the basic concepts behind packages. So come to an “expedition” with me: let us discover programming VSPackages! Do not forget: in this topic I am beginner, only a few steps ahead of you! This is a real expedition: I cannot paint the full roadmap in advance only for the few next steps. When we reach a milestone, we stop, we summarize where we are and set the next milestone with a few steps toward.
So, our first milestone is to have a good understanding what a package is, how it works what element it is built from. We start from practice: we are going to build a few very basic packages and look what is inside.
In the next post we are going to create the “Hello, world of packages” together.
Posted
Jan 02 2008, 06:49 PM
by
inovak