Every now and then, I get an interesting question or problem from a customer (thanks Uma) that highlights a need for some additional documentation, or at the least a sample or walkthrough to illustrate how to get from A to Z. In this instance, the question was "How do you localize a project (or item) template, to support multiple languages?". Better yet, what if that template uses a custom wizard assembly, and you want to deploy it with a VSIX package?
Given all the moving pieces involved, I've opted to break this down into a couple of different blog entries. The first being this one, which will walk you through creating the initial project. And then a follow up blog entry, that will detail the steps to localized the template, wizard assembly, and VSIX package.
To follow this walkthrough, you will need to install the Visual Studio SDK that matches the version of Visual Studio you are using. If you aren't sure where to find it, there is a list of useful links on the very first entry of this blog that I keep up to date with links to various downloads and resources. Note, while I used VS 2013 Ultimate to create this project, this same technique can be used for VS 2012 and VS 2010 (Pro or better SKUs).
Upon installing the Visual Studio SDK, the following project templates are added to assist you in developing new project and item templates.
These Project templates create a baseline project or item template, that when built, produces a .zip file that you can manually copy into your ...\Documents\Visual Studio 20xx\Templates directory, and then used to create a new project, or add a new item to an existing project.
The Visual Studio SDK, also includes a stand-alone "VSIX Project" template, which can be used to deploy a template (in addition to other assets).
These VSIX projects do not generate an assembly by default. But if you manually edit a few properties in the .csproj, you can use the VSIX project to build an assembly and have it included as a part of the .VSIX payload.
So instead of creating a solution with a structure similar to the following:
Solution - MyTemplateWithWizard - MyProjectTemplate (produces the template as a .zip file) - MyTemplateWizard (produces an assembly with an IWizard implementation) - MyTemplateWithWizardVSIX (packages the template and assembly into a .VSIX)
You can actually implement the wizard assembly with the VSIX project, simplifying the solution structure such that there are only two projects required. For example:
Solution - MyTemplateWithWizard - MyProjectTemplate (produces the template as a .zip file) - MyProjectWizard (builds the wizard assembly, packaging it and the template into a .VSIX)
The following is a walkthrough that will show you how to create a VSIX deployable project template with custom wizard support, using just the two projects as described above.
<?xmlversion="1.0"encoding="utf-8"?> <VSTemplateVersion="3.0.0"Type="Project" xmlns=http://schemas.microsoft.com/developer/vstemplate/2005xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010"> <TemplateData> <Name>My Project</Name> <Description>My Custom Project Template</Description> <Icon>MyProjectTemplate.ico</Icon> <ProjectType>CSharp</ProjectType> <RequiredFrameworkVersion>2.0</RequiredFrameworkVersion> <SortOrder>1000</SortOrder> <TemplateID>0504f2de-af7a-4065-a542-f65ca8c61790</TemplateID> <CreateNewFolder>true</CreateNewFolder> <DefaultName>MyProject</DefaultName> <ProvideDefaultName>true</ProvideDefaultName> </TemplateData> <TemplateContent> <ProjectFile="ProjectTemplate.csproj"ReplaceParameters="true"> <ProjectItemReplaceParameters="true"TargetFileName="Properties\AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem> <ProjectItemReplaceParameters="true"OpenInEditor="true">Class1.cs</ProjectItem> </Project> </TemplateContent> </VSTemplate>
<WizardExtension> <Assembly>MyProjectWizard, Version=220.127.116.11, Culture=neutral, PublicKeyToken=22c2a1a5fa7b6905</Assembly> <FullClassName>MyProjectWizard.MyProjectWizard</FullClassName> </WizardExtension>
And there you have it, a VSIX deployable template with a custom wizard support. When finished, use the resulting .VSIX file to deploy the template to your production environment. And if you think others will find your template useful, consider uploading it to the VS Extension Gallery.
The resulting code from the above walkthrough can be downloaded from here.