1. Preparation: Create and obtain API Keys on NuGet
Website: www.nuget.org/
1.1. You need to log in first, just log in directly with your Microsoft account

1.2. Click the menu API Keys in the upper right corner to create a Key

1.3. Fill in the information and create
Write here the name of the NuGet package you want to upload [Each NuGet package (corresponding to one name) can upload multiple versions]

1.4. Copy API Key

2. Make a simple dll
Create a new "library" project with the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1
{
public class Class1
{
public static int Add(int a, int b)
{
return a + b;
}
public static int Sub(int a, int b)
{
return a -b;
}
}
}
框架使用.NET Framework 4.6.1,这个在后面也会使用到,输出类型使用类库:

Generate the following dll:

3. Create a publishing folder
为了更好管理文件,在E:\nuget新建MyPackage_Star302Test文件夹,存放所需的文件

4. Upload and publish NuGet package
4.1. 方法一:使用命令行上传,需要下载nuget.exe
4.1.1. 到https://www.nuget.org/downloads下载nuget.exe

4.1.2. Configure nuget environment variables
把下载的 nuget.exe 放到
E:\nuget打开电脑属性–高级系统设置–环境变量–系统变量,选择 Path–编辑–新建–填写
E:\nuget,确定

Once the environment variables are configured, you can use the nuget instruction
4.1.3. Generating nuspec file
Use the nuget spec command to produce.nuspec files


.nuspec 文件中的内容为xml格式,如下,可以简单了解:

The changed content is:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>PackageTest</id>
<version>1.0.0</version>
<authors>Star302</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<!-- <icon>icon.png</icon> -->
<projectUrl>http://project_url_here_or_delete_this_line/</projectUrl>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>$copyright$</copyright>
<tags>Tag1 Tag2</tags>
<dependencies>
<group targetFramework=".NETStandard2.1">
<dependency id="SampleDependency" version="1.0.0" />
</group>
</dependencies>
</metadata>
</package>
4.1.4. Generating nupkg file
使用nuget pack命令生产.nupkg 文件


4.1.5. Copy the API Key of 1.4 and upload it to NuGet

Run the following command:
nuget push PackageTest.1.0.0.nupkg xxxkey -Source https://api.nuget.org/v3/index.json
[I tried several times but failed, I don't know why]

4.2. Method 2: To upload using the interface tool, you need to download NuGet Package Explorer [Recommended!]
4.2.1. Download NuGet Package Explorer
https://www.microsoft.com/zh-cn/p/nuget-package-explorer/9wzdncrdmdm3?activetab=pivot:overviewtab
4.2.2. Create a new Package

4.2.3. Add lib folder, add net461 folder, add existing files



4.2.4. Edit uploaded data
这里选择Edit Metadata,Edit Metadata Source 则是 xml 文件格式的

Change some parameters:

Add project dependencies, that is, which frameworks you rely on. Such as. NET Framework,. NET Standard, etc.


Finally, click Confirm

Editing completed, check the effect

Looking at the content corresponding to the Metadata Source, it is actually consistent with the information just edited.


4.2.5. Save nupkg file


4.2.6. Published to NuGet


Successfully released:

Check in Visual Stuido:

5. Management of NuGet packages
Just go to https://www.nuget.org/and explore it yourself. It's very simple.





Reference: blog.csdn.net/weixin_38211198/article/details/118438071
Copyright statement: This article is an original article by CSDN blogger "Ming Like Noon" and follows the CC 4.0 BY-SA copyright agreement. Please attach a link to the original source and this statement to reprint it.
Original link: blog.csdn.net/sinat_40003796/article/details/130407108