Publish NuGet Packages in .NET Core

Problem

How to create and publish NuGet package in .NET Core

Solution

First setup is to have a registry setup to host the packages, I’ll use nuget.org.

Register a free account at www.nuget.org

Go to “API Keys” section of your account:

Create a new key by giving it a name, scopes (permissions) and selecting packages (* means all):

You’ll see a new key added, copy the key by clicking on the “Copy” link and paste it somewhere safe:

Now that you have a registry and key to upload your packages, let’s create and push a package. I am using here a simple .NET Core class library I wrote to work with CSV files, the source code can be found on GitHub. You can of course use any of your projects.

Open a Command Prompt in your project directory:

Run dotnet pack command to create a NuGet package (by default this will also build the project):

Options used are:

  • -o is the path where package is created
  • -c specifies build configuration
  • --version-suffix specifies that this is a pre-release. You can omit this for your final release

You’ll have the NuGet package created in the publish folder:

Run dotnet nuget push command to upload NuGet package to nuget.org:

Options used are:

  • -s specifies the URL to server where you’re uploading the package
  • -k specifies the API key that identifies you on the server

Browse to your NuGet website and you’ll find your package:

You could also specify other properties in .csproj that adds metadata to your NuGet package, e.g.:

Run dotnet pack command again and open the package in NuGet Package Explorer to view the properites:

For more information on various properties you could set, please see details here.

2 comments

Leave a Reply