-
Notifications
You must be signed in to change notification settings - Fork 205
How to create a project template
In this article, I will show you how to create a project template.
Steps to add a new project template to SideWaffle
- Fork SideWaffle if you haven't already and open
SideWaffle.sln
- Add the source project to the solution
- Right click your VSIX project and select
Add->Template Reference
- Right click your source project and
Add New Item->Extensibility\SideWaffle Project Template Files
. This adds 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.
Below is a 5 minute video demonstrating how to create a new project template with SideWaffle.