NuGet打包类库并上传教程 - 码农阿亮
source link: https://www.cnblogs.com/wml-it/p/16536944.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
1 . 下载 Download NuGet.exe
2 . windows 系统下设置环境变量 path中 或者 在dos 命令窗口下cd转到 nuget.exe 所在目录,这里为了每次使用方便,设置环境变量。
第一步:将下载的的NuGet.exe
放到一个指定目录下,之后不要删除和移动,切记。
第二步:配置环境变量,向系统变量
中,将刚才存放NuGet.exe
路径追加到path
中。
3 .在Nuget官网 注册一个账号,并获取一个API Key。
第一步:登录,这里可以选择微软账号登录。
第二步:设置API Key
第三步:管理和获取Key
二、打包项目
1.新建里一个测试类库,书写部分类和方法
2.编辑AssemblyInfo.cs 信息
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Aliang.XmlHelper")]
[assembly: AssemblyDescription("一个简单的Xml帮助类库")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("暂无")]
[assembly: AssemblyProduct("Aliang.XmlHelper")]
[assembly: AssemblyCopyright("Copyright © P R C 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("5de5ae77-900c-4709-83dd-76c89718da63")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
3.以Release模式发布代码,然后右击项目
->在终端中打开
4.终端中执行命令,提示成功创建.nuspec
文件成功
nuget spec
5.根据需要编辑.nuspec
文件
$$符号代表的是变量值
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Aliang</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<!-- <icon>icon.png</icon> -->
<projectUrl>https://gitee.com/mingliang_it</projectUrl>
<description>一个简单的Xml帮助类库 </description>
<releaseNotes>初始版本</releaseNotes>
<copyright>$copyright$</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
</package>
三、上传项目
1.生成上传文件包
执行命令 : nuget pack [项目名].csproj
用release编译打包:nuget pack [项目名].csproj -Prop Configuration=Release
nuget pack Aliang.XmlHelper.csproj -Prop Configuration=Release
2.在项目根目录下,已经生成好打包文件了
3.上传 nug.org 服务器
第一步:获取APIKey
上面已经Copy获取到的APIKey
第二步:设置APIKey,这个命令只需要第一次上传的时候执行,以后就不需要了
nuget setApiKey [Your-API-Key] -Source [Nuget官网上package路径]
nuget setApiKey 【替换成你的API-Key】 -Source https://www.nuget.org/api/v2/package/
第三步:上传文件包
nuget push [nupkg名称] nupkg -Source [Nuget官网上package路径]
nuget push Aliang.XmlHelper.1.0.0.nupkg -Source https://www.nuget.org/api/v2/package/
4.查看上传文件包
5.下载安装文件包
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK