Have you ever wondered how to write project templates similar to those that come out of the box in Visual Studio? In this talk we will discuss what goes into the creation of a multi-project template, how to package the template into a Visual Studio 2010 Extension file (VSIX), and how to best distribute your template to other developers. We will do this with an example of an F# multi-project template.
4. Setup the projects (including the VSIX proj. ) Create the project vstemplate metadata files Setup the project collection vstemplate file Compress the files and add to the VSIX proj. Build the project and test your VSIX package. 5 Easy Steps
Why would you want to build a template?Standards for your development teamIncrease productivity when starting a new projectProvide an example of your new framework in useHelp others get started with a particular framework or technology
This is a one-time requirement. The VS2010 SDK adds a number of project templates including the one needed to create VSIX packages.Do the following to see the new VSIX C# project template once installation is complete:Type Ctrl+Shift+NNavigate to Visual C# -> Extensibility and locate the VSIX Project template.
5 Easy Steps to Creating a Multi-project Template:Setup the projects with files, references, etc. just the way that you want them. (see the FSharpWP7BasicTemplate example).Make sure to also add a VSIX project to the solution. Much of the information within the VSIX can be completed during this step. While in VS2010, double-click the source.extension.vsixmanifest file to view and update the VSIX manifest information.Create the *.vstemplate by doing the following:Use the Export Template wizard to export each of the projects that should be included in the template.Choose the Project template type and click NextEnter what ever information is desired on the template options page, unselect the “automatically import the template into Visual Studio” checkbox, then click Finish.Extract the *.zip file that was created during the export template process.Copy the MyTemplate.vstemplate file to the directory that contains the project file for the project for which you exported the template.Repeat as needed.Setup the project collection vstemplate fileCreate a new file called {ProjectName}.vstemplate at the same level as your solution file.Using the FSharpWP7App.vstemplate provided in the sample application that accompanies this deck, update the name and description information as you wish it to be displayed in Visual Studio when an individual attempts to create a project with your template.Add ProjectTemplateLink elements to the ProjectCollection element for each project.Compress the files and add to the VSIX proj. created in step 1.Compress the directories containing the projects as well as the project collection vstemplate file into a single {project name}.zip file.Copy the compressed file into the ProjectTemplates directory of the VSIX project. (Note: If you wish to have the project template appear in a sub-category in Visual Studio, add a sub-directory to the ProjectTemplates directory and place the compressed file within it. You’ll also need to add this directory and file to the ProjectTemplates folder of the VSIX project in Visual Studio.)In VS2010, open the VSIX manifest, scroll to the bottom, and click the Add Content button.Select Project Template content type Select the source of File, locate the compressed file that was placed in the ProjectTemplates directory (or the associated sub-directory), then click ok.Build the project and test your VSIX package.You can now build the VSIX project.Launch the *.VSIX that was created in the bin\\Debug or bin\\ReleaseRestart Visual Studio and you should now see your project under the Visual F# project category when typing Ctrl+Shft+NTest it all out to make sure that it works.
How do you distribute your template?Upload the VSIX package to Visual Studio GalleryPeople can then use VS2010 to find and install your template (Ctrl+Shift+N -> Select Online Templates -> search…)To upload your template to Visual Studio GalleryNavigate to http://visualstudiogallery.msdn.microsoft.com/Select Upload (this will prompt you to sign in, if you haven’t already)Select Project or Item template and click NextClick Choose File, select the previously created VSIX package, and click next.Complete the rest of the wizard to make your project template available.There are a number of validation rules that apply when uploading to Visual Studio Gallery, but that don’t always apply to a launching a VSIX package locally. For instance, there is a path length limination of 260 characters. This path length limitation takes into account the length and depth of the template naming including the Product Name of the template that is provided in the VSIX manifest file. If you receive an error that says “Path may be too long in VSIX”, try shortening the names of the directories, files, and/or Product Name that make up your VSIX. You may also run into issues when attempting to upload DLLs or EXEs. To help avoid this, remove the bin and obj directories from the various projects that makeup the template before compressing them (step 4 from the previous slide).
You can find the sample referenced in this deck (as well as many others) on my GitHub (https://github.com/dmohl/FSharpWP7BasicTemplate).