问题描述
我有一个Visual Studio 2017项目模板扩展,当前正在与ASP.NET项目一起使用.它具有以下.vstemplate:
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>
另外,引用它的VSIX文件具有
Additionally the VSIX file referencing it has
设置项目的"VSIX子路径"属性.
set for the "VSIX Sub Path" property of the project.
但是,我无法让此模板出现在ASP.NET Core项目中.我尝试在vstemplate中使用它:
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>
(来自 https://stackoverflow.com/a/38543920/1783619 ),但是它没有用.在发布的Visual Stuido 2017版本中,如何使项目模板显示在.NET核心项目中?
(from https://stackoverflow.com/a/38543920/1783619) 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?
推荐答案
为哈巴狗文件创建项目模板时,我遇到了同样的问题.
I had this same issue while creating an item template for pug files.
这是我所做的:
首先,我了解了库存模板的编写方式:
Firstly, I found out how the stock templates are written in:
C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Professional \ Common7 \ IDE \ ItemTemplates \ AspNetCore
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ItemTemplates\AspNetCore
这是我的模板的外观:
<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>
要注意的领域:ProjectType,TemplateGroupId,TemplateId(由您自己组成)和NumberOfParentCategoriesToRollUp
Areas to pay attention to:ProjectType, TemplateGroupId, TemplateId(make up your own) and NumberOfParentCategoriesToRollUp
我希望模板主要显示在内容"类别中,在该类别中,HTML和CSS类型的模板都放置在
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
我必须创建一些目录(AspNetCore \ Web \ Content)才能获得此结构.
I had to create a few directories (AspNetCore\Web\Content) to get this structure.
然后将"NumberOfParentCategoriesToRollUp"设置设置为2,可以使模板显示在内容"类别中,也可以汇总"并显示在Web和AspNetCore类别中.
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:
然后,当您完成所有操作后,打开Visual Studio 2017开发人员命令提示符并键入:
Then when you are all done, open a visual studio 2017 developer command prompt and type:
devenv /updateconfiguration
这篇关于应使用哪些设置来获取与.NET Core项目一起使用的自定义ItemTemplates?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!