How to make a professional NuGet package? teach-by-doing! Super detailed! Absolutely!

catalogue

1, Create and get API Keys on NuGet

1. First, you need to log in. You can log in directly with a Microsoft account

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

3. Fill in information

4. Get Key

2, Create project

1. Create project

2. Generate dll

3. Create a publishing folder

3, Upload NuGet

1. Upload using the command line

2. Publish using NuGet Package Explorer

4, NuGet package management

1. Management Pack

2. Delete

1, Create and get API Keys on NuGet

website: https://www.nuget.org/

1. First, you need to log in. You can log in directly with a Microsoft account

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

3. Fill in information

I will directly fill in the item name here as the Key Name

4. Get Key

Click the Copy button to obtain the Key

2, Create project

1. Create project

Frame usage NET Framework 4, which will also be used later, and the output type uses the class library

2. Generate dll

After completing the project, use the Release mode to generate the dll

3. Create a publishing folder

In order to better manage files, create a new WinForm in E:\nuget Movecontrol folder to store the required files

explain:

Icon.png file, as the icon of nuget package, it is found that jpg is not supported. Only png can be used

readme.md file, introduction file, will be displayed in https://www.nuget.org/packages/WinForm.MoveControl/ display

WinForm.MoveControl.dll file, project file

3, Upload NuGet

There are two methods to upload NuGet

1. To upload using the command line, you need to download nuget exe

2. To upload using interface tools, you need to download NuGet Package Explorer

1. Upload using the command line

1.1 to https://www.nuget.org/downloads Download nuget exe

1.2 configuring nuget environment variables

Put the downloaded nuget Exe to E:\nuget

Open computer properties - advanced system settings - environment variables - system variables, select Path - Edit - New - fill in E:\nuget, OK

After the environment variables are configured, you can use the nuget instruction

1.3 generate nuspec file

Use the nuget spec command to produce nuspec file, in xml format

<?xml version="1.0"?>
<package >
  <metadata>
    <id>Package</id>
    <version>1.0.0</version>
    <authors>GreAmbWang</authors>
    <owners>GreAmbWang</owners>
    <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
    <projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
    <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2021</copyright>
    <tags>Tag1 Tag2</tags>
    <dependencies>
      <dependency id="SampleDependency" version="1.0" />
    </dependencies>
  </metadata>
</package>

You can modify the information inside. I'm not used to this method. The parameters inside will be introduced below

1.4 generating nupkg files

Use the nuget pack command to produce nupkg file

1.5 upload to nuget

Direct use of function commands

nuget push Package.1.0.0.nupkg xxxkey -Source https://api.nuget.org/v3/index.json

In this way, the upload is completed. The second method is recommended

2. Publish using NuGet Package Explorer

2.1 download NuGet Package Explorer

https://www.microsoft.com/zh-cn/p/nuget-package-explorer/9wzdncrdmdm3?activetab=pivot:overviewtab

NuGet Package Explorer can directly open a file in nupkg format

2.2 refer to log4net writing format

Let's directly open a published nuget and take a look at log4net

Open it with NuGet Package Explorer. You can refer to the preparation in it

2.3 create a new Package

2.4 add lib folder

2.5 add net40 folder

2.6 adding existing files

Add the file, it's like this

2.7 editing and uploading data

I select Edit Metadata here, and the Edit Metadata Source is in xml file format

Fill in information

If you need to add project dependencies, which frameworks do you rely on, such as NETFramework,. NETStandard et al

After editing, see the effect

The xml format in Edit Metadata Source is like this

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>WinForm.MoveControl</id>
    <version>1.0.5</version>
    <title>WinForm.MoveControl 1.0.5</title>
    <authors>GreAmbWang</authors>
    <owners>GreAmbWang</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <icon>Icon.png</icon>
    <projectUrl>https://greambwang.blog.csdn.net/article/details/118424770</projectUrl>
    <description>WinForm.MoveControl Can set control drag, adjust control size and position.
It is very simple to use and execute a sentence of code, such as button1.SetMove();</description>
    <summary>set up WinForm Control drag and drop to adjust the size and position of the control</summary>
    <releaseNotes>Release 1.0.5</releaseNotes>
    <copyright>Copyright ©  2021 GreAmbWang</copyright>
    <language>zh-Hans-CN</language>
    <tags>GreAmbWang, WinForm</tags>
    <readme>readme.md</readme>
    <dependencies>
      <group targetFramework=".NETFramework4.0" />
    </dependencies>
  </metadata>
</package>

Save nupkg file

file

2.8 publish to nuget

Enter in nuget key on ORG

After the release, it needs to be reviewed. It takes about two minutes

Install on NuGet

Ha ha, done

4, NuGet package management

1. Management Pack

NuGet Package Explorer,nuget. Comparison of information in org and nuget

2. Delete

nuget package cannot be deleted, but the corresponding version is hidden

In Listing, uncheck the unneeded version, and it will not be displayed in NuGet search

Packages that publish errors can be set by hiding the version

This is my last project

WinForm.MoveControl

Can set control drag, adjust control size and position.
It is very simple to use and execute a sentence of code, such as button1 SetMove();

Project article introduction:

https://greambwang.blog.csdn.net/article/details/118424770

GitHub: https://github.com/GreAmbWang/WinFormProjects

nuget: https://www.nuget.org/packages/WinForm.MoveControl/

reference resources

https://blog.csdn.net/qq_35260798/article/details/108467688

https://docs.microsoft.com/zh-cn/nuget/nuget-org/overview-nuget-org

Keywords: github Visual Studio VS nuget

Added by Teach on Sat, 22 Jan 2022 15:53:02 +0200