第5篇 如何制作并上传自己的项目模版并生成nuget程序包

轻松快捷创建自己的nuget包,具体步骤如下

1. 创建content文件夹,存放模版源码(bin和obj都不要,只留源码),

image
image

在content下再创建:.template.config/template.josn,

image

template.josn 文件格式如下

{
  "$schema": "http://json.schemastore.org/template",
  "author": "Chenshibao",
  "classifications": [ "Web/WebApi" ],
  "name": "ChenShiBao.AspNetCore7.0 DotNet",
  "identity": "ChenShiBao.AspNetCore7.0.Template", 
  "shortName": "csbaspnet7tpl",
  "tags": {
    "language": "C#" ,
   "type": "project"
  },
  "sourceName": "ChenShiBao.AspNetCore7.0", /*此处与解决方案名称一致,安装项目时自动替换成项目名称*/
 "preferNameDirectory":true
}

2.创建license文件夹,并创建一个license.txt文件:可以不写license内容

image

3.官网下载nuget.exe程序拷到与content同级目录

image

4.打开控制台,cmd切换到content同级目录,执行nuget spec命令,生成对应的ChenShiBao.AspNetCore7.0.Template.nuspec文件

image

5.新建一个Package.bat文件,内容如下,双击Package,生成项目模版 ChenShiBao.AspNetCore7.0.Template.1.0.0.nupkg

nuget pack ChenShiBao.AspNetCore7.0.Template.nuspec
pause

你可以打开查看并修改包里的内容
image

6.注册nuget账号【已有就登录】,提交ChenShiBao.AspNetCore7.0.Template.1.0.0.nupkg 项目模板,同时生成一个nuget的apiKey,等待一段时间,就可以在vs2022中看到

image
image
image

7.等nuget生效后,重新打开vs2022,就可以创建自己的项目模版了

image

posted @ 2024-08-22 11:39  似梦亦非梦  阅读(33)  评论(0编辑  收藏  举报