What settings should be used to get custom ItemTemplates working with .NET Core projects?
Asked Answered
M

2

8

I have a Visual Studio 2017 item template extension that is currently working with ASP.NET projects. It has the following .vstemplate:

<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010">
  <TemplateData>
    <Name>Angular Component</Name>
    <Description>Files for an Angular component</Description>
    <RequiredFrameworkVersion>4.5</RequiredFrameworkVersion>
    <Icon>AngularComponentTemplate.ico</Icon>
    <ProjectType>CSharp</ProjectType>
    <ProjectSubType>Web</ProjectSubType>
    <NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
  </TemplateData>
  <TemplateContent>
    <ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.component.html">base.component.html</ProjectItem>
    <ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.component.ts">base.component.ts</ProjectItem>
  </TemplateContent>
</VSTemplate>

Additionally the VSIX file referencing it has

ItemTemplates\CSharp\Web

set for the "VSIX Sub Path" property of the project.

I cannot, however, get this template to appear in ASP.NET Core projects. I tried using this in the vstemplate:

<ProjectType>DNX</ProjectType>
<TemplateGroupID>SharedDotNetAndDotNetWeb</TemplateGroupID>

(from https://mcmap.net/q/1326608/-visual-studio-2015-asp-net-core-rc2-loss-of-custom-item-templates) but it didn't work. In the released version of Visual Stuido 2017, how do I get item templates to appear in .NET core projects?

Mimesis answered 17/5, 2017 at 16:41 Comment(0)
S
10

I had this same issue while creating an item template for pug files.

Here is what I did:

Firstly, I found out how the stock templates are written in:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ItemTemplates\AspNetCore

This is how my template looks:

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
  <TemplateData>
    <DefaultName>page.pug</DefaultName>
    <Name>Pug File</Name>
    <Description>This is a basic pug file template (previously Jade)</Description>
    <ProjectType>CSharp</ProjectType>
    <TemplateGroupID>AspNetCore</TemplateGroupID>
    <TemplateID>AspNetCore.Pug</TemplateID>
    <NumberOfParentCategoriesToRollUp>2</NumberOfParentCategoriesToRollUp>
    <Icon>__TemplateIcon.ico</Icon>
    <PreviewImage>__PreviewImage.ico</PreviewImage>
    <SortOrder>10</SortOrder>
    <ShowByDefault>false</ShowByDefault>
  </TemplateData>
  <TemplateContent>
    <References />
    <ProjectItem ReplaceParameters="true">page.pug</ProjectItem>
  </TemplateContent>
</VSTemplate>

Areas to pay attention to: ProjectType, TemplateGroupId, TemplateId(make up your own) and NumberOfParentCategoriesToRollUp

I wanted my template to show up mainly in the "Content" category, where the HTML and CSS type templates were so I placed my zip file in

Visual Studio 2017\Templates\ItemTemplates\Visual C#\AspNetCore\Web\Content

I had to create a few directories (AspNetCore\Web\Content) to get this structure.

Then the setting "NumberOfParentCategoriesToRollUp" set to 2 allows the template to display in the "Content" category, but also "roll up" and show in Web and AspNetCore categories.

More info on organization of templates here:

https://learn.microsoft.com/en-us/visualstudio/ide/how-to-locate-and-organize-project-and-item-templates

Then when you are all done, open a visual studio 2017 developer command prompt and type:

devenv /updateconfiguration
Squarerigged answered 29/5, 2017 at 0:38 Comment(0)
P
2

The most important thing is

<TemplateGroupID>AspNetCore</TemplateGroupID>

Otherwise you will not see your item template from ASP.NET core project.

Strange thing is that you will see your item template with other project (desktop for example).

Hoping that Microsoft will document or make things easier one day

Paske answered 30/8, 2018 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.