The official source of product insight from the Visual Studio Engineering Team
One of the great new features we added in Visual Studio 2010 is the ability to easily find and consume online Project and Item templates without leaving the New Project/Item dialog. What may not be so obvious is how to go from a piece of code you want to share to a template contained in a VSIX file that can be uploaded to the Visual Studio Gallery or shared with others in your organization.
This post describes two ways (one quick and simple, the other for more complex situations) to create a VSIX file that contains your shareable code templates.
In a series of posts on Visual Studio 2010 Beta 1 (Part 1, Part 2, Part 3, Addendum), Pedro Silva walked through the process of using the standard Export Template wizard that has shipped in Visual Studio for several releases in combination with the VSIX Explorer tool or the VSIX Project template in the Visual Studio SDK to package up your template. While this does the job, it seemed like a few too many steps for something that should be straightforward.
To make this process much simpler, we recently published a new Export Template as VSIX wizard that will guide you through the process of turning an existing project into a VSIX file containing your template. After downloading the Export Template as VSIX wizard from the Visual Studio Gallery website or the Extension Manager dialog, you will find a new option on the File menu in Visual Studio 2010 for “Export Template as VSIX…”. This will bring up the Export Template as VSIX Wizard, which will allow you to configure options for both the template and the VSIX file that will contain it.
While this is the ideal way to quickly share some starter code with others, it is not ideal for all situations where you’re creating a template. For example, you may be building a series of templates in conjunction with a VSPackage or editor extension. What if you are making frequent changes to the template files? What if you wish to keep the template source files in a version control system? What if you need to make a customization to the templates or the VSIX container not permitted by the Export Template as VSIX wizard?
This is where the Visual Studio SDK comes in to help. In the Visual Studio 2010 SP1 SDK, we’ve included project templates for building project and item templates. (Yes, we’ve created templates for templates.) If you go to the Extensibility node under Visual C# or Visual Basic in the New Project dialog, you’ll find two new templates (for either a project template or an item template). Let’s walk through the process of creating and packaging a C# Project template using these new templates in the Visual Studio SDK.
First, we'll create a project template project which generates a zip file for a single template. Then, we'll create a VSIX project to contain and deploy the generated project template.
<VSTemplate Include="MyTemplate.vstemplate"> <OutputSubPath>Windows</OutputSubPath></VSTemplate>
<VSTemplate Include="MyTemplate.vstemplate"> <OutputSubPath>Windows</OutputSubPath><Culture>1041</Culture></VSTemplate>
There are a few other interesting points about the support in the SDK for building templates:
While not as simple as the “Export Template as VSIX” wizard, this technique allows you to build templates and deliver them using the VSIX format while still keeping control over the template source files.
Aaron Marten - Developer, Visual Studio Platform
Short Bio: Aaron has been on the Visual Studio team for 6 years with a focus on extensibility. For Visual Studio 2010, Aaron worked on the Extension Manager and the Visual Studio SDK. In addition to contributing to the Visual Studio blog, he also writes about extending the IDE on his own blog at http://blogs.msdn.com/aaronmar.