VSIX Tutorial-Adding a simple template
Setup the template project
- Add C# Item Template, create a project named MyExtension.IniParserTemplate
- Create a file tiniTemplate.tini, it will be the root item
[IniSetup]
Locale=en-US
- Rename class1 to tiniTemplate.cs
- Set the compile action for this .cs file to "none"
- Set the new project items inside the .vstemplate file. This will tell that
- ReplaceParameters: During the application of the templates a list of key value pair is present. Those will be replaced inside the file and will be used insde the .vstemplate file.
- TargetFileName: The file name that will be generated. This can contains paths. As in the .cs file that is considered the "child" of the .tini file.
- ItemType: Optional. Content means that it will not be included or compiled. If nothing is specified the file will be considered according to the extension
- Inner text: The filename inside the template project
<ProjectItem
ReplaceParameters="true"
TargetFileName="$fileinputname$.tini"
ItemType="Content">tiniTemplate.tini</ProjectItem>
<ProjectItem
ReplaceParameters="true"
TargetFileName="$fileinputname$.tini\$fileinputname$.cs" >tiniTemplate.cs</ProjectItem>
- ...and change the default name to "IniTemplate.tini"
Include the template project inside the main project
- Add the reference to the MyExtension.IniParserTemplate project
- Set the properties of the assembly just included
- Output Groups Included in VSIX: "TemplateProjectOutputGroup;" The group in which the item will be placed.
- Reference Output Assembly: "false" It is not needed since the template will be included as a zip file by the build system
- Template Type: "Item" We are creating an item template
- VSIX Sub Path: "ItemTemplates\My Extension" The path inside the Visual Studio Wizard.
- Open the .vsixmanifest and add the new asset, relative to the MyExtension.IniParserTemplate. The %CurrentProject% variable is used as a reference
<Asset
Type="Microsoft.VisualStudio.ItemTemplate"
d:Source="Project"
d:ProjectName="%CurrentProject%.IniParserTemplate"
d:TargetPath="|MyExtension.IniParserTemplate;TemplateProjectOutputGroup|"
Path="ItemTemplates"
d:VsixSubPath="ItemTemplates" />

Conclusion
Now everything is in place!
You can download the code
Last modified on: November 28, 2013