美文网首页菜鸟学编程
使用nuget打包类库并发布

使用nuget打包类库并发布

作者: 菜鸟飞不动 | 来源:发表于2019-04-12 00:04 被阅读6次

    前言

    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

    img

    修改生成的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安装类库

    相关文章

      网友评论

        本文标题:使用nuget打包类库并发布

        本文链接:https://www.haomeiwen.com/subject/efjfwqtx.html