<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>1.0.0</PackageVersion>
<PackageId>KnownTemplate</PackageId>
<Title>KnownTemplate</Title>
<Authors>KnownChen</Authors>
<Description>Project Template for Known.</Description>
<PackageTags>dotnet-new;templates;Known</PackageTags>
<TargetFramework>net7.0</TargetFramework>
<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>
<NoWarn>$(NoWarn);NU5128</NoWarn>
</PropertyGroup>
<ItemGroup>
<Content Include="Template\**\*" Exclude="Template\**\bin\**;Template\**\obj\**" />
<Compile Remove="**\*" />
</ItemGroup>
</Project>
在Template下再创建文件夹Template,把解决方案模板复制进去
注意:解决方案所有文件不要使用Template词语,否则创建项目时将文件中的Template替换成项目名称
在Template/Template文件夹在创建.template.config文件夹
在.template.config文件夹下创建template.json文件,内容如下
{
"$schema": "http://json.schemastore.org/template",
"author": "KnownChen",
"classifications": [ "Template" ],
"name": "KnownTemplate",
"identity": "KnownTemplate",
"shortName": "known",
"tags": {
"language": "C#"
},
"sourceName": "Template" /*此处与解决方案名称一致,安装项目时自动替换成项目名称*/
}
dotnet pack
dotnet new install KnownTemplate
dotnet new known --name=TIMS
创建成功提示如下图
TIMS项目模板创建结果如下图