簡體   English   中英

應該使用哪些設置來獲取使用.NET Core項目的自定義ItemTemplates?

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

我有一個Visual Studio 2017項目模板擴展,目前正在使用ASP.NET項目。 它有以下.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文件具有

的ItemTemplate \\ CSHARP \\ WEB

設置為項目的“VSIX子路徑”屬性。

但是,我不能讓這個模板出現在ASP.NET Core項目中。 我嘗試在vstemplate中使用它:

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

(來自https://stackoverflow.com/a/38543920/1783619 )但它沒有用。 在Visual Stuido 2017的發布版本中,如何讓項目模板出現在.NET核心項目中?

我在為pug文件創建項目模板時遇到了同樣的問題。

這是我做的:

首先,我發現了股票模板的編寫方式:

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

我希望我的模板主要顯示在“內容”類別中,其中HTML和CSS類型模板是這樣我將我的zip文件放入

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

我不得不創建一些目錄(AspNetCore \\ Web \\ Content)來獲得這個結構。

然后將設置為“NumberOfParentCategoriesToRollUp”的設置設置為2允許模板顯示在“內容”類別中,還可以“匯總”並顯示在Web和AspNetCore類別中。

有關模板組織的更多信息,請訪問:

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

然后,當您完成所有操作后,打開Visual Studio 2017開發人員命令提示符並鍵入:

devenv /updateconfiguration

最重要的是

<TemplateGroupID>AspNetCore</TemplateGroupID>

否則,您將無法從ASP.NET核心項目中看到您的項目模板。

奇怪的是,您將看到您的項目模板與其他項目(例如桌面)。

希望微軟有一天能夠記錄或使事情變得更容易

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM