共用方式為


VS2010 Tutorial: Building VS Extensions with the Beta 1 SDK

The SDK is used to create extensions to Visual Studio itself like those you can find on VS Gallery.  You can download it here.  The installation is done on top of an existing install of VS 2010 and gives you a set of build tools, templates, and a short cut for debugging devenv.exe (VS) that can be used for testing your new extensions.

Once you get the SDK installed, you will find a new set of templates.  Let’s start by doing File, New Project.  Type ‘editor’ in the search box to find example editor extensions:

image

Select the ‘Editor Text Adornment’ template and click OK.  This sample template extends the editor with a Text Adornment which basically gives you the ability to change how text is displayed.  By default this adornment finds all instances of the character ‘a’ and highlights them.

Build the solution (Ctrl+Shift+B).  The template automatically packages the new .dll into a .vsix file (basically a zip with some dialogs, the code, and other data required to extend VS).  It then copies the new package into the Extensions directory for the test instance of VS:

image

Now hit F5 to debug the new extension.  Because you are extending Visual Studio itself, the test instance of VS is launched:

image

This is a separate instance of devenv.exe as shown by tlist:

image

Notice the key difference is devenv.exe is launched with a special /rootsuffix flag which gives it a different instance for the extension location:

image

In the experimental instance of VS, open a text file (such as the one generated for this add-in).  When it loads, you’ll notice the editor extension is in effect and has drawn a red box around every ‘a’ in the file:

image

image

The code is pretty straightforward.  The constructor sets up a event handler for layout changed, whenever the change happens every line is scanned, within each line when an ‘a’ is found a red box is placed around it.

If you open the .vsixmanifest file you will get an editor for all the settings an extension needs:

image

This includes things like the images you will see when you browse / install the extension, the description, etc. 

Extensions can be easily shared with your friends.  To install an extension, either double click the VSIX file to install it or copy the unzipped extension contents to your extensions directory.

In addition to local usage, you can also publish (or acquire) extensions from the VS Gallery.  This is easy to do from inside VS by choosing Tools, Extension Manager:

image

If you select the Online Gallery, you will find all the controls, templates, and tools from the public site:

image

You can easily download and install an extension by selecting it and hitting the Download button. In this case I’ll download the Demo Dashboard which is one of our samples:

image

After you download the file (assuming you accept the license), you will be prompted to restart VS so the extension can be loaded:

image

If you select Restart Now, VS will start again and restore your state.  The new extension is now in place:

image

Once you have written an extension you really like and you think others may want, you can use the VS Gallery site to upload your item:

image

You can update, delete, etc your extension after it is uploaded.

As you can see, loading new items, creating new items, etc is very straightforward.  I’m looking forward to seeing what you come up with.

Enjoy!

Comments

  • Anonymous
    June 01, 2009
    PingBack from http://www.nhanlife.com/vs2010-tutorial-building-vs-extensions-with-the-beta-1-sdk/5572/1396/

  • Anonymous
    June 02, 2009
    It's pretty cool when you General Manager is out working with the bits you just released. Jason just

  • Anonymous
    June 02, 2009
    I've been working on an extension but its more a solution level extension not an editor extension. I'm getting entirely lost trying to figure out the Visual Studio SDK. The MSDN documentation for it is even more confusing. It took me a while to just be able to get a list of all the files in a solution. In the end it was looking at the code of an extension on CodePlex that I was finally able to actually get a working reference to DTE. None of the msdn examples worked... I feel like I'm just missing something. What I'm looking for is a good site/book/resource for understanding the mess I'm seeing with all these dll's, DTE3, Solution4 confusions. It would be good to note the VSPackage solution template is really nice to start off an extension, adding unit tests and the framework for adding a menu item and tool window. I did do a blog post on starting off VS2010 extensions, also covering more parts of the VSIX file.

  • Anonymous
    June 03, 2009
    Thank you for submitting this cool story - Trackback from DotNetShoutout

  • Anonymous
    June 03, 2009
    It's always great to see your General Manager excited about a feature you worked on. It's nice to see

  • Anonymous
    June 03, 2009
    Cool post. Thanks. Looking forward to having one.

  • Anonymous
    June 04, 2009
    Would be helpful if there was a meatier example of an editor adornment. Is there a way to conveniently work with the code model of the C# source file being edited, and get ranges from that, instead of just analysing the plain text? Do we just use the existing DTE API, and if so, how do we get to it from the interfaces to the Wpf editor?

  • Anonymous
    June 04, 2009
    Software Development Tools TestDriven.Net 2.22: Support for Visual Studio 2010 Beta 1 Typemock Isolator 5.3.1 is Out! NDepend: Product Review Free Web Hosting to try ASP.NET 4 Beta1, VS2010 Beta 1, and MS Web Deployment Tool RC1 Microsoft Web Platform

  • Anonymous
    June 04, 2009
    new eye candy. nothing new. cashing cow.

  • Anonymous
    June 08, 2009
    Lots of good stuff this week – not one, not two, but three posts worthy of ‘Pick of the week’ treatment! Picks of the Week I Hardly Recognize You Fighting Technical Debt with the Wall of Pain A Different Shade of Rose, or “How to…actually, I’m not up