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

落爺英雄遲暮 提交于 2019-12-05 03:51:12

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://docs.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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!