After you install the Visual Studio customization SDK, a number of new extensibility projects are available for you to create. These projects are templates that demonstrate how to perform various Hello World-type customizations that you can then build on. Figure 2-15 shows these new project types.
The following extensibility projects are available:
VSIX Project: This is an empty extension that contains just the minimum references needed and a manifest file that describes the extension.
Editor Margin: This creates a green box down the bottom of code editor frame.
Editor Classifier: This formats certain types of text a blue color.
Editor Text Adornment: This is a template that highlights all instances of the letter a.
Editor Viewport Adornment: This template creates a purple box in the top-right corner of IDE and a Windows Forms toolbox control.
Let's take a look at the Editor Margin extensibility project.
Open up Visual Studio and create a new Editor Margin project called Chapter2.EditorMargin.
Open MarginFactory.cs and note how it utilizes the MEF [Export] attribute (the other attributes contain various bits of metadata utilized by the IDE):
[Export(typeof(IWpfTextViewMarginProvider))] [Name("GreenBar")] //Ensure that the margin occurs below the horizontal scrollbar [Order(After = PredefinedMarginNames.HorizontalScrollBar)] //Set the container to the bottom of the editor window [MarginContainer(MarginContainerAttribute.Bottom)] //Do this for all content types [ContentType("text")] [TextViewRole(PredefinedTextViewRoles.Interactive)] internal sealed class MarginFactory : IWpfTextViewMarginProvider { public IWpfTextViewMargin CreateMargin(IWpfTextViewHost textViewHost, IWpfTextViewMargin containerMargin) { return new GreenMargin(textViewHost.TextView); } }
Let's do something a bit crazy and tell Visual Studio to rotate the text editor 245 degrees. Open MarginFactory.cs and add the following using statement:
using System.Windows.Media;
Build and run this project, and the IDE will launch a special test instance containing your extension (this may take a bit of time, so be patient).
Once the test instance has loaded, create a new console project. Voila! As you can see, the text editor is rotated and a green "Hello world!" box is created at the base of the editor (Figure 2-16).
Note how the text editor still works just as you would expect with syntax checking, IntelliSense, and so on (although the scrollbars behave a little strangely).
Now that you have created a useful extension for rotating a text editor, what if you want to share it with your friends/victims? When extensions are compiled, they are built as .vsix files that you can install by double-clicking them or copying them to the extensions directory at C:Program FilesMicrosoft Visual Studio 10.0Common7IDEExtensions.
The Extension Gallery (see Figure 2-17) allows you to download a number of additions from new project templates to make IDE customizations. A number of extensions for VS2010 are available already, some with source code. To open the Extension Gallery, select Extension Manager on the Tools menu and then select the Online Gallery option.
WHAT ABOUT EXISTING EXTENSIONS CREATED WITH THE PREVIOUS API?Microsoft says that more than 80 percent of existing IDE customization will be supported through the use of shims (code that maps the old API methods to the new). It is important to note, however, that Microsoft plans to remove these shims in the next version of Visual Studio after VS2010. |
It is worth noting that starting with VS2008, Microsoft opened up the ability to make use of the IDE for your own applications. This is called the Visual Studio Shell. A popular project using the Visual Studio Shell is the add-on studio for the online game World of Warcraft (http://addonstudio.codeplex.com).
For more information on the Visual Studio Shell, please refer to http://msdn.microsoft.com/en-us/vsx2008/products/bb933751.aspx.
3.16.48.143