I'm having trouble with a custom item templates not showing on "Add New Item" in Visual Studio 2022.
The template was created by using "Export as Template" from an ASP.NET Core project in VS2022 with the "Automatically import into Visual Studio" option selected. The template is successfully exported and appears in the %USER_NAME%\Documents\Visual Studio 2022\Templates\ItemTemplates directory.
The item however does not appear as a template when trying to add via "Add New Item" in an ASP.NET Core 7.0 project.
However the item does appear when adding to .NET Framework 4.7.2 project. This tells me VS it at least picking up the the template.
.vstemplate code:
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<DefaultName>IndexTest.cshtml</DefaultName>
<Name>IndexTest</Name>
<Description><No description available></Description>
<ProjectType>CSharp</ProjectType>
<SortOrder>10</SortOrder>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<References />
<ProjectItem SubType="" TargetFileName="$fileinputname$.cshtml" ReplaceParameters="true">Index.cshtml</ProjectItem>
<ProjectItem SubType="" TargetFileName="$fileinputname$.cshtml.cs" ReplaceParameters="true">Index.cshtml.cs</ProjectItem>
</TemplateContent>
</VSTemplate>
The template is deployed to the root of the ItemTemplates directory.
How do I get this template to appear in ASP.NET Core projects?
I tried adding the <TemplateGroupID>AspNetCore</TemplateGroupID> element with no luck.
Check if the article "Creating custom Item templates in Visual Studio" from Deepak H A could help.
It discusses the "
Automatically import the template into Visual Studio" option. Since you have already used this option and your template appears in theItemTemplatesdirectory, this part seems correctly implemented.The importance of the
ReplaceParametersattribute in the.vstemplatefile is highlighted. That attribute allows dynamic replacement of parameters like$rootnamespace$and$safeitemname$, making sure the template adapts to the project where it is used.Crucially, the article confirms your attempt to use
<TemplateGroupID>AspNetCore</TemplateGroupID>in the.vstemplatefile. That is the correct approach to make the item template appear in ASP.NET Core projects. It is important that this tag is correctly placed inside the<TemplateData>section of the.vstemplatefile.