.net core 自定义项目模板

1,准备好一个项目

 2,安装模板

打开cmd,运行dotnet new -i D:\Abp\HmCoreAbpTemplate

安装本地模板后会列表出现 

 3,通过nuget包安装自定义模板

一,创建一个文件,文件内容如下

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>1.0</PackageVersion>
<PackageId>HmCoreAbpTemplate</PackageId>
<Title>HmCoreAbpTemplate</Title>
<Authors>caihuaxing</Authors>
<Description>eshop4.0 code template.</Description>
<PackageTags>dotnet-new;templates;contoso</PackageTags>
<TargetFramework>netstandard2.0</TargetFramework>

<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>
</PropertyGroup>

<ItemGroup>
<Content Include="HmCoreAbpTemplate\**\*" Exclude="HmCoreAbpTemplate\**\bin\**;HmCoreAbpTemplate\**\obj\**" />
</ItemGroup>

</Project>

 二,执行dotnet命令, dotnet pack --no-build 生成nuget包

 

 

 三,上传nuget包到nuge服务源

四,从nuget服务源安装模板到本地

运行命令:dotnet new -i HmCoreAbpTemplate --nuget-source wbp.nuget 

 

 五,根据模板创建项目:dotnet new hmca -n HmCore.EShop.Order

五,自动改版本号并创建包和上传包

备注:dotnet 命令:

1,查看安装的模板:dotnet new -l

2,安装模板: dotnet new -i D:\Abp\HmCoreAbpTemplate

3,删除模板:dotnet new -u D:\Abp\HmCoreAbpTemplate

4,安装nuget 包到本地dotnet new -i 包的PackageId --nuget-source 包源(可以从vs程序包源查看,例如: http://xxx.xxx.xxx.xxx/nuget)

5,生成包:dotnet pack --no-build (--no-build:打包时不执行生成程序)

6,创建项目:dotnet new hmca -n 解决方案名称 -o 生成项目路径

7,查看包源列表:nuget list -Source (包源地址,例如: http://xxx.xxx.xxx.xxx/nuget)

dotnet new hmca -n 解决方案名称 -o 生成项目路径

原文地址:https://www.cnblogs.com/caihuaxing/p/13051668.html