Reader rating:
Click here to read 1 comment about this article.
Article source: CoDe (2008 - Vol. 5 - Issue 1 - Extensibility)


Article Pages: < Previous - 1 2 3  4 


Visual Studio SDK Tips and Tricks (Cont.)

Visual Studio Extensibility Demystified

Since we (the VSX team) have placed the VS 2005 SDK 3.0 on the Microsoft Download Center, many developers have downloaded the SDK. The developers who are using the SDK now are no longer just developers who build commercial VSIP products. Users of the SDK now include students and developer enthusiasts who are building Visual Studio extensions to make their work more productive or just for fun and curiosity.

To that end, I’d like to spend a little bit of time explaining the various levels of Visual Studio extensibility to help developers who are new to the Visual Studio platform get ramped up.

Within the Visual Studio environment itself, there are three levels of extensibility: macros, add-ins and VSPackages.

Macros

Macros are the easiest way for developers to quickly gain access to Visual Studio’s underlying automation object model. If you hit Alt+F11 in Visual Studio, the Macros IDE will appear and here you can start writing your macro. Macros are sometimes called the "duct tape" of Visual Studio because of their versatility and flexibility. You can easily combine Visual Studio commands or set automation properties to create interesting behaviors. Listing 4, for example, illustrates a very simple macro that toggles the word wrap text editor option.

If you are interested in learning more about how to create, record, and use macros, I suggest that you go to http://msdn2.microsoft.com/en-us/library/b4c73967(VS.80).aspx for some resources.

So when should you use macros as the VS extensibility model? The scenarios that are great for using macros are those where you are trying script Visual Studio to automate certain tasks, provided that you can accept several limitations:

  • You can only write macros in Visual Basic.
  • To share macros with others, you must give them your macro projects which will include source code. Since the user of the macros can see the source code, there is no protection of your intellectual property.
  • Some extensibility scenarios cannot be achieved via macros. For example, you cannot create a new tool window, a new editor or a new project system via macros.

Scripting the IDE is powerful and often useful in many scenarios. But if you want to do more than duct-taping, you will need to develop Add-ins or VSPackages.

Add-ins

Similar to macros, add-ins also leverage on the automation object model of Visual Studio. But unlike macros, add-ins are compiled into binary code so your intellectual property can be protected. Perhaps more importantly, add-ins allow you to seamlessly integrate new tool windows, plug in options pages, dynamically enable commands, and add branding onto the splash screen and Help About boxes-scenarios that macros do not enable. Features offered by add-ins can fit seamlessly into the IDE as if they were a part of Visual Studio. In implementation, you also have the choice of creating add-ins in C#, Visual Basic or C++.

You can find many great add-ins in the community today. Visual Studio Hacks has a list of interesting add-ins at http://www.visualstudiohacks.com/type/addins.

James Avery has written a great MSDN article about the ten must-have tools at http://msdn.microsoft.com/msdnmag/issues/04/07/MustHaveTools/default.aspx (some of which are add-ins) for Visual Studio. A couple of student interns from the C# team have created some interesting add-ins that enhance code navigation and editing.

As you can see, you can use add-ins to build tools and features that support a large number of scenarios. The automation object model is extremely powerful. To get a sense of what this automation object model looks like, you can refer to the automation object model chart at http://msdn2.microsoft.com/en-gb/library/za2b25t3(VS.80).aspx.

If you are interested in learning more about how to create add-ins, a good place to get started is http://msdn2.microsoft.com/en-us/library/5abkeks7(VS.80).aspx.

VSPackages

VSPackages are the most powerful way to extend Visual Studio. Using VSPackages (a.k.a. VSIP interfaces), you gain access to the same API that internal teams at Microsoft have to integrate anything you want inside Visual Studio. This deep level of integration allows developers to build everything that add-ins enable, plus more. With VSPackages, you can even build custom project systems, debuggers, editors, data designer extensions, and language integrations. IronPython is a great example of a language integration project built with VSPackages, and you can find this sample integration in the Visual Studio SDK.

By the way, the Visual Studio SDK is a great way to start learning about how to use this powerful mechanism to deeply integrate with Visual Studio. You can view the online documentation at http://msdn.com/vsx. It is easy to get started with VSPackages once you have the SDK installed because it provides wizards to help you create your first command, tool window or editor via VSPackages. In Visual Studio 2005, the Managed Package Framework has made VSPackage development a lot easier.

You can request a PLK through the http://vsipmembers.com site. Simply register for an account (it’s free!) and fill out the information in the list below in order to request a PLK. And you need to make sure the information you entered in the PLK request process remains unchanged in your code. The VSIP site will generate the PLK based on the following pieces of information:

  • Company Name
  • Package GUID
  • Product Name
  • Product Version
  • Minimum Product Edition

If you change any of this information in your VSPackage, you will need to re-request a new PLK through the Web site.

Levels of Extensibility in Visual Studio

Visual Studio is a great extensibility platform that offers developers many choices for how they want to customize and extend their development environment to meet their unique needs. Whether you choose macros, add-ins or VSPackages depends on your scenarios. In general, you can use these rule-of-thumbs:

  • If you are trying to automate tasks in the IDE quickly and you are fine with distributing your code in source code form, macros may be the most appropriate.
  • If you want to distribute your code in binary form, and the automation object model satisfies your needs, try using an add-in.
  • If you want to create a custom project system, editor, debugger or language service, you will need to use VSPackages.

Conclusion

For more tips and tricks for VSX, check out my blog at http://blogs.msdn.com/dr._ex/default.aspx and the blogs of various VSX team members linked to on the VSX Team blog at http://blogs.msdn.com/vsxteam. Now I’m going back into the VSX laboratory to work on some new cool extension ideas for Visual Studio.

Dr. Ex represents the VS Ecosystem team's as a VSX expert! You can find his blog at http://blogs.msdn.com/dr.ex/.

Dr Ex

&


Article Pages: < Previous - 1 2 3  4 

Page 1: Visual Studio SDK Tips and Tricks
Page 2: Using IVsProfferCommands to Retrieve a Visual Studio CommandBar
Page 3: Debugging Package Load Failures
Page 4: Visual Studio Extensibility Demystified

Average rating:
2.3 out of 5

15 people have rated this article.