使用nuget打包類庫並發布


前言

NuGet 是免費、開源的包管理開發工具,專注於在 .NET 應用開發過程中,簡單地合並第三方的組件庫。今天的目的就是記錄一下如何打包一個類庫,並發布到官網。在開始之前需要在www.nuget.org上注冊一個賬號,下載最新版本的nuget命令行工具https://dist.nuget.org/win-x86-commandline/latest/nuget.exe,並添加到環境變量中。

開始打包自己的類庫

1.修改項目程序集信息AssemblyInfo.cs

我這里要打包的類庫Zeroes.WeixinSDK來源於https://github.com/night-king/weixinSDK開源項目,修改完信息后重新生成一下。

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Zeroes.WeixinSDK")]
[assembly: AssemblyDescription("ZeroesSuit快速開發框架微信SDK庫")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Zeroes")]
[assembly: AssemblyProduct("Zeroes.WeixinSDK")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("135e92df-8241-4d2c-97aa-910e1c53af81")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.1")]
[assembly: AssemblyFileVersion("0.0.0.1")]

 

2.命令行下使用nuget spec命令生成Zeroes.WeixinSDK.nuspec打包配置文件

打開命令行定位到Zeroes.WeixinSDK項目所在目錄,輸入命令:nuget spec

修改生成的nuspec文件,內容如下:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
    <projectUrl>http://www.cnblogs.com/zeroes</projectUrl>
    <iconUrl>http://files.cnblogs.com/files/zeroes/Z.ico</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <releaseNotes>Zeroes.WeixinSDK封裝了微信api的調用方法,可以方便的調用。</releaseNotes>
    <copyright>Copyright 2016</copyright>
    <tags>Zeroes</tags>
  </metadata>
</package>

 

3.打包類庫

打開命令行定位到Zeroes.WeixinSDK項目所在目錄,輸入命令:nuget pack Zeroes.WeixinSDK.csproj

4.發布類庫

登陸www.nuget.org網站,打開https://www.nuget.org/packages/manage/upload地址。

點擊“Upload”上傳后,顯示信息確認頁面,然后點擊 “Submit”,發布完成,來張諜照:

 

5.使用nuget安裝類庫

 

參考文章:http://www.cnblogs.com/daxnet/archive/2013/05/07/3064577.html#3527602

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM