Publishing a NuGet Package

NuGet is the package manager for .NET. It is used by developers to create, share, and consume .NET libraries.

For more information about NuGet, see An introduction to NuGet.

Table of Contents

  1. What is a package?
  2. Add package metadata to project file
  3. Create a NuGet.org account
  4. Create your NuGet API key
  5. Create a secret for the NuGet API key in your GitHub repository
  6. Other sources and inspiration

What is a package?

A package is a compiled library with its descriptive metadata.

Add package metadata to project file

To publish a NuGet package, you need to add some metadata to your project file (.csproj). Here is an example of the necessary properties to include:

<PropertyGroup>
    <PackageId>IbanFR.SemanticRelease.LiftButton</PackageId>
    <Version>0.1.0</Version>
    <Authors>Iván Fernández</Authors>
    <Company>IbanFR</Company>
    <Description>Csharp implementation of the LiftButton software</Description>
</PropertyGroup>

PackageId should be unique across NuGet.org. For example, you can prefix it with your GitHub username: <PackageId>YourGitHubUsername.SemanticRelease.LiftButton</PackageId>.

Create a NuGet.org account

To create a NuGet.org account, you need to have a personal Microsoft account. If you don’t have one, you can create it here.

Make sure to enable two-factor authentication (2FA) for your Microsoft account, as it is required to publish NuGet packages. Instructions for enabling 2FA can be found at How to turn two-step verification on or off for your Microsoft account.

Once you have your Microsoft account ready, follow the steps from the Individual accounts on NuGet.org to create your NuGet.org account.

Create your NuGet API key

To create your NuGet API key, follow instructions at Acquire an API key.

Create a secret for the NuGet API key in your GitHub repository

To securely store your NuGet API key in your GitHub repository, you need to create a secret.

Follow the instructions at Use secrets in GitHub Actions to create a new secret named NUGET_TOKEN and set its value to your NuGet API key.

Other sources and inspiration