-
Notifications
You must be signed in to change notification settings - Fork 205
How to create a project template (old technique)
This doc covers how to create a project template. The experience to create a project template has significantly changed in December 2013.
Note: we have a new easier way to create project templates. See the new approach at How to create a project template
Watch this 5 minute video on how to create project templates with SideWaffle.
http://www.youtube.com/watch?v=BH64h6Elz4o
Steps to add a new project template to SideWaffle
- Fork SideWaffle if you haven't already and open
SideWaffle.sln
- Copy the project that you want to use as a template under the side-waffle folder
- Add the project to the solution
- In the TemplatePack project add a reference the project you just added
- Add the following files to the target project to turn it into a template
-
_preprocess.xml
(_Must be in the root folder, and must define thePath
attribute onTemplateInfo
_Definitions\_project.vstemplate.xml
For the steps where you add the _preprocess.xml
and _Definitions\_project.vstemplate.xml
files there is an item template that you can use to create these files for you. To use it right click on the the project you want to turn into a project template and select Add New item and then select the SideWaffle Project Template Files template. You can see this template in the image shown below. (Note: this requires that you have SideWaffle installed)
You should always add the item to the root directory of your project. It will create the files in the correct location. Here is more info on those files.
-
_preprocess.xml
- This file is used for the following; to perform file replacements during the template packing process and to override the path where the template is shown in the New Project/Item dialog. -
_Definitions\_project.vstemplate.xml
- This file contains metadata regarding your template. For example the name, description, logo, etc are all found in this file. This file also has a pointer to the project file that you are creating a template out of.
You'll need to update _preprocess.xml
so that it replaces your namespace values to use $safeprojectname$
when the template is created and so that you define where the template should be shown in the New Project dialog. Below is an example of a complete file.
<?xml version="1.0" encoding="utf-8" ?>
<Preprocess>
<TemplateInfo Path="CSharp\Web\Custom\Subcategory"/>
<Replacements Include="*.*" Exclude="*.vstemplate;*.csproj*.jpg;*.png;*.ico;_preprocess.xml">
<add key="_SampleProjRef" value="$safeprojectname$"/>
</Replacements>
</Preprocess>
You'll need to update the _Definitions\_project.vstemplate.xml
file and ensure that the correct content for the File
attribute on the Project
element was generated. Below is an example of a complete file.
Note: Make sure to set the Path attribute on TemplateInfo here otherwise the template will never be shown
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>Sample proj from ref</Name>
<Description>Sample proj from ref</Description>
<DefaultName>MyProjApp</DefaultName>
<ProjectType>CSharp</ProjectType>
<ProjectSubType></ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>icon.png</Icon>
<!-- Indicates how many parent folders this item template should appear in -->
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
</TemplateData>
<TemplateContent>
<Project TargetFileName="$projectname$.csproj" File="_SampleProjRef.csproj" ReplaceParameters="true">
</Project>
</TemplateContent>
</VSTemplate>
After you have made these changes you can party on your project and then when you build the TemplatePack project the project template will be included automatically.
You can find a sample of this in the SideWaffle repo as the _SampleProjRef
project.