NuGet 上发布自己的类库包
一、配置环境
1.1 NuGet 官网注册一个账号,创建一个 API key.
1.2 下载 NuGet命令行工具,放到一个系统目录下,方便在不同地方启动。
1.3 命令行启动 NuGet 命令行工具,设置 ApiKey
1
| nuget setApiKey <my_api_key>
|
二、编辑包描述文件
2.1 项目目录下(非解决方案)启动 NuGet 命令行工具,运行下面命令生成一个与项目同名的 .nuspec 文件,即:包描述文件
2.2 编辑包描述文件,详细可参考官方文档
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| <?xml version="1.0"?> <package> <metadata> <id>ReoGrid.Mvvm<</id> <version>$version$</version> <title>ReoGrid Mvvm <</title> <description>a class library for the ReoGrid binding model</description> <authors>IUpdatable</authors> <owners>IUpdatable</owners> <releaseNotes>The initial version</releaseNotes> <licenseUrl>https://github.com/IUpdatable/ReoGrid.Mvvm/blob/master/LICENSE</licenseUrl> <projectUrl>https://github.com/IUpdatable/ReoGrid.Mvvm</projectUrl> <repository type="git" url="https://github.com/IUpdatable/ReoGrid.Mvvm" /> <iconUrl>https://api.nuget.org/v3-flatcontainer/unvell.reogrid.dll/2.1.0/icon</iconUrl> <requireLicenseAcceptance>true</requireLicenseAcceptance> <copyright>Copyright 2018 IUpdatable</copyright> <tags>ReoGrid Binding MVVM WPF Grid Spreadsheet Excel Drawing Chart</tags> <dependencies> <dependency id="Newtonsoft.Json" version="11.0.1" /> <dependency id="MongoDB.Bson.signed" version="2.5.0" /> </dependencies> </metadata> <files> <file src="build\**" target="build" /> <file src="bin\Release\Common.Utility.dll" target="lib/net462" /> <file src="bin\Release\SquirrelFramework.Configurations.dll" target="lib/net462" /> </files> </package>
|
三、生成 NuGet Package
3.1 在确定我们的 Project 版本号设定正确后(如果是再次发布,记得将版本号递增),首先在 Release 模式下 Rebuild 代码。
3.2 随后,在项目目录打开 CMD,运行以下 NuGet 命令。
1
| nuget pack yourProject.csproj -Properties Configuration=Release -Properties NuspecFile=yourProject.nuspec
|
四、发布
1
| nuget push yourProject.X.X.X.nupkg -Source https://www.nuget.org/api/v2/package
|
参考
- 如何在 NuGet 发布自己的类库包
- 官方文档