How to create and publish a package to Nuget.org
A NuGet package can be published to any location.
- Open a NuGet Account.
This is quite straightforward.
- From the NuGet Account page, expand the Login Account option, and enable ‘two factor authentication’.
- Create a NuGet API Key.
> From the User menu, select ‘API Keys’.
This will display the API Keys page.
> On the API Keys page, expand the Create option.
This will reveal the Create API Form.
- Enter a unique Key Name,
- Set the Scope to ‘Push’ and ‘Push new packages and package versions’.
- Set the ‘Glob Pattern’ to *.
- Click the Create button to finish.
- Copy the API Key to a local file.
You will need it later.
Note, you can only copy the API key value once.
- Ideally, you will need to upload a digital certificate file (.cer).
Note, this step is not necessary to test and demonstrate this procedure.
NuGet packages can include a digital signature that provides protection against tampered content. This signature is produced from an X.509 certificate that also adds authenticity proofs to the actual origin of the package.
Signed packages provide the strongest end-to-end validation. There are two different types of NuGet signatures:
Author Signature. An author signature guarantees that the package has not been modified since the author signed the package, no matter from which repository or what transport method the package is delivered. Additionally, author-signed packages provide an extra authentication mechanism to the nuget.org publishing pipeline because the signing certificate must be registered ahead of time. For more information, see Register certificates.
Repository Signature. Repository signatures provide an integrity guarantee for all packages in a repository whether they are author signed or not, even if those packages are obtained from a different location than the original repository where they were signed.
Further information on Signing Packages can be found at:
- Download and install NuGet.exe
- After downloading copy nuget.exe to ‘C:\Program Files (x86)\NuGet\’
- Add nuget.exe to your machine ‘path’.
Control Panel > System > Advanced System Settings > Environment Variables > Select and edit Path
Add ‘C:\Program Files (x86)\NuGet\‘ to the path.
- From within your Visual Studio project, display the project Properties page.
From the Build tab,
- Set the Configuration to be ‘Active (Release)’,
- Set the Output path to be ‘bin\Release\lib\net472\’
Note, the .Net version folder should be appropriate to your particular project setting.
- Build your project.
- Open a command window, and
- change the directory to the root directory of your Visual Studio project.
- From the command window prompt, generate a NuGet spec file.
- type C:\My Project Directory> nuget spec [your project name]
e.g. nuget spec myuniqueproject
This action will generate a .nuspec file located in the root directory of your project.
- Leave the command window open.
- Modify and change the default values of the NuGet spec file (.nuspec)
As a minimum, you must set the following values:
- Set the id to a unique name.
- Set the license values correctly.
- Change the description to an alternative value.
- Change the releaseNotes to an alternative value.
- Change the tags to an alternative value.
- From the command window prompt, generate a NuGet package file.
- type C:\My Project Directory> nuget pack [your project name].nuspec -NoDefaultExcludes
e.g. nuget pack myproject.nuspec -NoDefaultExcludes
This will generate a .nupkg file located in the root directory of your project.
The format will be [NuGet package id].[NuGet version number].nupkg
- From the command window prompt, publish your NuGet package file.
- type C:\My Project Directory> nuget push [NuGet Package file] [NuGet API Key] -Source https://api.nuget.org/v3/index.json
e.g. nuget push MyUniqueProject.1.0.0.nupkg MyAPIKey -Source https://api.nuget.org/v3/index.json
This will generate a response message in the command window:
Pushing MyUniqueProject.1.0.0.nupkg to ‘https://www.nuget.org/api/v2/package‘…
WARNING: All published packages should have license information specified.
Learn more: https://aka.ms/deprecateLicenseUrl.
1. Created https://www.nuget.org/api/v2/package/ 1234ms
Your package was pushed.
- From within NuGet.org, display your published packages.
- Click the ‘Manage Packages’ menu, (https://www.nuget.org/account/Packages)
This will display the Packages page.
- Expand the Published Packages section.
This will display your published package.
That completes the basic steps required to publish a NuGet package.
A useful resource https://docs.microsoft.com/en-us/nuget/what-is-nuget