1.新建一个.NET Core类库
2.新增一个方法,并编译项目
3.下载Nuget.exe,与刚才新建的类库放在同一目录下
下载地址:https://www.nuget.org/downloads
下载一个发包工具,自己选一个版本下载,一般都是选择最新版
4.将类库打包
4.在Nuget官网注册账号
创建一个Key
Key Name 和 Glob Pattern 名称一样就好
创建完成后点击copy,保存起来。因为以后无法再次复制密钥!!!
5.找到vs对应的开发人员命令提示
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools
6.命令提示定位到Nuget.exe所在的目录
双击运行 Developer Command Prompt for VS 2019
cd到类库的目录
7.通过命令 nuget setapikey xxxxx (第4步生成的key), 设置API Key
通过命令 nuget setapikey xxxxx-xxxx-xxx-xxxx-xxxx-xxxx , 设置API Key;
8.项目属性
9. 生成xxxx.nuspec文件
nuspec是NuGet将项目打包成nupkg的输入文件,可以通过nuget spec命令产生。
通过命令 nuget spec 生成xxxx.nuspec文件;
10.生成 xxxx.nupkg文件
注意一定时在
bin\Debug
文件夹下
通过命令 NuGet pack xxxxxx.csproj 生成xxxx.nupkg文件
11.NuGet发布到服务器
通过命令 nuget.exe push xxxxx.nupkg -Source https://www.nuget.org ,将NuGet发布到服务器。
12.使用
参考文章1:https://docs.microsoft.com/zh-cn/nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli
参考文章2:https://www.cnblogs.com/May-day/p/13562386.html
翻译:https://www.cnblogs.com/chuankang/p/10076082.html
微信公众号:net分享
注意
注释:参考文章1可能存在找不到命名空间的问题
会存在·The assembly ‘lib\project.dll’ is placed directly under ‘lib’ folder. It is recommended that assemblies be placed inside a framework-specific folder. Move it into a framework-specific folder.·