What is Nuget
Nuget is an open source project under the .NET platform, which is an extension of Visual Studio . When using Visual Studio to develop .NET Framework-based applications, Nuget makes adding, removing and updating references in a project faster and easier.
Detailed Encyclopedia: https://baike.baidu.com/item/NuGet/5296055?fr=aladdin
Publish your own library package (Library Package)
Step1: Register on NuGet and get API Key
Official website address: https://www.nuget.org/
If you are already logged in, select
Get APIKey
After the establishment is completed, there is a Copy button below this, click to get the ApiKey
Step2: Download NuGet.exe, configure the command line tool
Download address: http://nuget.codeplex.com/downloads/get/669083
Configure the local computer environment variable Path path:
Right click My Computer---->Properties---->Advanced System Settings
After the configuration is complete, use the Win+R keys, enter cmd, and click Enter to enter the command line
After entering nuget, the above information is displayed, that is, the configuration is successful.
Step3: Configure the global push source address
Use the following command to configure
1 // Configure the simulated push source to nuget.org 2 nuget config -Set DefaultPushSource=nuget.org
Step4: Set Api Key
Use the following command to set the Nuget API Key:
1 // Replace my_api_key below with the API Key obtained in STEP 1 2 nuget setApiKey my_api_key
Step5: Develop your own class library
Source code:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace DemoDll 8 { 9 public class Demo 10 { 11 public string Hello() 12 { 13 return "Hello"; 14 } 15 } 16 }
Open the AssemblyInfo.cs file and set the property value
1 using System.Reflection; 2 using System.Runtime.CompilerServices; 3 using System.Runtime.InteropServices; 4 5 // General information about assemblies is controlled by the following 6 // . Changing these attribute values modifies 7 // Information associated with the assembly. 8 [assembly: AssemblyTitle( "" )] 9 [assembly: AssemblyDescription( "" )] 10 [assembly: AssemblyConfiguration( "" )] 11 [assembly: AssemblyCompany( "" )] 12 [assembly: AssemblyProduct( "" )] 13 [assembly: AssemblyCopyright( " Copyright © 2018 " )] 14 [assembly: AssemblyTrademark( "" )] 15 [assembly: AssemblyCulture( "" )] 16 17 // Set ComVisible to false to make types in this assembly 18 // Not visible to COM components. If you need to access type 19 in this assembly from COM // Set the ComVisible attribute of this type to true. 20 [assembly: ComVisible( false )] 21 22 // If this project is exposed to COM, the following GUID is used for the ID of the type library 23 [assembly: Guid( " 437fac93-d41d-48c4-9e64-dd96c1a0cd8f ")] 24 25 // The version information of the assembly consists of the following four values: 26 // 27 // Major version 28 // Minor version 29 // Generation number 30 // Revision number 31 // 32 // All can be specified value, the version number and revision number can also be preset using "*" as shown below 33 // by using "*" as shown below: 34 // [assembly: AssemblyVersion("1.0.*")] 35 [assembly : AssemblyVersion( " 1.0.0.0 " )] 36 [assembly: AssemblyFileVersion( " 1.0.0.0 " )]
Step6: Generate the nuspec file and modify it
At the command prompt, go to the directory where the xxxx.csproj file is located, and execute:
1 // Generate nuspec file command 2 nuget spec
1 // The command prompt prompts 2 that "ML.Common.SDK.nuspec" has been successfully created.
Open this file xxxx.nuspec with your favorite text editor
1 <?xml version="1.0"?> 2 <package > 3 <metadata> 4 <id>$id$</id> 5 <version>$version$</version> 6 <title>$title$</title> 7 <authors>$author$</authors> 8 <owners>$author$</owners> 9 <requireLicenseAcceptance>false</requireLicenseAcceptance> 10 <description>$description$</description> 11 <copyright>Copyright 2018</copyright> 12 <tags>Tag1 Tag2</tags> 13 </metadata> 14 </package>
Precautions:
1. $description$ is replaced with the value of AssemblyDescriptionAttribute. Before generating the package, you must remember to compile the project first, otherwise it will prompt an error that $description$ cannot be found
2. If there is no releaseNotes, delete this node directly. If there is, fill in your own content, do not use the default content, otherwise a warning message will be generated in the next step
3. The authors node and description node cannot be deleted, otherwise an error will be reported
Step7: Generate a library package (Library Package)
In the xxxx.csproj directory, execute the following command to generate the class library package:
Note: NuGet will use the assembly generated by the default project configuration for packaging. If the project defaults to Debug and you need to package it with Release, use the following command
1 // Generate class library package 2 nuget pack .\ML.Common.SDK.csproj -Prop Configuration=Release
Step8: Publish the class library package to Nuget.org
Issue with the following command:
1 // Publish the class library package 2 nuget push .\ML.Common.SDK. 1.0 . 0.1 .nupkg