How to: Create Item Templates
The steps in the first procedure of this topic show you how to create an item template by using the Export Template wizard.
If you plan to use the item in a Windows Store app project, you’ll have to perform a few extra steps. The second procedure in this topic helps you accomplish that task.
Note
You cannot export templates for C++ projects.
To add a custom project item template to the Add New Item dialog box
Create or open a project in Visual Studio.
Add an item to the project and modify it if you want to.
Modify the code file to indicate where parameter replacement should take place. For more information, see How to: Substitute Parameters in a Template.
On the File menu, click Export Template.
Click Item Template, select the project that contains the item, and click Next.
Select the item for which you want to create a template, and click Next.
Select the assembly references to include in the template, and click Next.
Type the icon file name, preview image, template name, and template description, and click Finish.
The files for the template are added to a .zip file and copied to the ..\Users\username\Documents\Visual Studio Version\Templates\ItemTemplates\ folder.
To enable the item template to be used in a Windows Store project
Follow the steps in the procedure above to export an item template.
Extract the .vstemplate file from the .zip file that was copied to the ..\Users\username\Documents\Visual Studio Version\Templates\ItemTemplates\ folder.
Open the .vstemplate file in Notepad.
In the .vstemplate file, add the following XML within the opening and closing <TemplateData> tag: <TemplateGroupID>WinRT-Managed</TemplateGroupID>.
The following example shows the entire contents of a .vstemplate file after the line of XML <TemplateGroupID>WinRT-Managed</TemplateGroupID> has been added to it.
<VSTemplate Version="3.0.0" xmlns="https://schemas.microsoft.com/developer/vstemplate/2005" Type="Item"> <TemplateData> <DefaultName>MyItemStoreTemplate.xaml</DefaultName> <Name>MyItemStoreTemplate</Name> <Description>This is an example itemtemplate</Description> <ProjectType>CSharp</ProjectType> <SortOrder>10</SortOrder> <Icon>__TemplateIcon.ico</Icon> <TemplateGroupID>WinRT-Managed</TemplateGroupID> </TemplateData> <TemplateContent> <References /> <ProjectItem SubType="Designer" TargetFileName="$fileinputname$.xaml" ReplaceParameters="true">MyItemTemplate.xaml</ProjectItem> <ProjectItem SubType="Code" TargetFileName="$fileinputname$.xaml.cs" ReplaceParameters="true">MyItemTemplate.xaml.cs</ProjectItem> </TemplateContent> </VSTemplate>
In Notepad, save the .vstemplate file and close it.
Copy and paste the .vstemplate file back to the .zip file located in the ..\Users\username\Documents\Visual Studio Version\Templates\ItemTemplates\ folder.
If the Copy File dialog box appears, choose the Copy and Replace option.
You can now add an item based on this template to a Windows Store project by using the Add New Item dialog box.