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!