108 lines (69 sloc) 4.32 KB
title description author ms.topic
Creating and publishing a NuGet package using the dotnet CLI
A walkthrough tutorial on creating and publishing a NuGet package using the .NET Core CLI, dotnet.

Quickstart: Create and publish a package (dotnet CLI)

It's a simple process to create a NuGet package from a .NET Class Library and publish it to using the dotnet command-line interface (CLI).


  1. Install the .NET Core SDK, which includes the dotnet CLI.

  2. Register for a free account on if you don't have one already. Creating a new account sends a confirmation email. You must confirm the account before you can upload a package.

Create a class library project

You can use an existing .NET Class Library project for the code you want to package, or create a simple one as follows:

  1. Create a folder called AppLogger and change into it.

  2. Create the project using dotnet new classlib, which uses the name of the current folder for the project.

Add package metadata to the project file

Every NuGet package needs a manifest that describes the package's contents and dependencies. In a final package, the manifest is a .nuspec file that is generated from the NuGet metadata properties that you include in the project file.

  1. Open your project file (.csproj) and add the following minimal properties inside the existing <PropertyGroup> tag, changing the values as appropriate:


    [!Important] Give the package an identifier that's unique across or whatever host you're using. For this walkthrough we recommend including "Sample" or "Test" in the name as the later publishing step does make the package publicly visible (though it's unlikely anyone will actually use it).

  2. Add any optional properties described on NuGet metadata properties.

    [!Note] For packages built for public consumption, pay special attention to the PackageTags property, as tags help others find your package and understand what it does.

Run the pack command

To build a NuGet package (a .nupkg file) from the project, run the dotnet pack command, which also builds the project automatically:

# Uses the project file in the current folder by default
dotnet pack

The output shows the path to the .nupkg file:

Microsoft (R) Build Engine version for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 29.91 ms for D:\proj\AppLoggerNet\AppLogger\AppLogger.csproj.
  AppLogger -> D:\proj\AppLoggerNet\AppLogger\bin\Debug\netstandard2.0\AppLogger.dll
  Successfully created package 'D:\proj\AppLoggerNet\AppLogger\bin\Debug\AppLogger.1.0.0.nupkg'.

Automatically generate package on build

To automatically run dotnet pack when you run dotnet build, add the following line to your project file within <PropertyGroup>:


Publish the package

Once you have a .nupkg file, you publish it to using the dotnet nuget push command along with an API key acquired from

[!INCLUDE publish-notes]

Acquire your API key

[!INCLUDE publish-api-key]

Publish with dotnet nuget push

[!INCLUDE publish-dotnet]

Publish errors

[!INCLUDE publish-errors]

Manage the published package

[!INCLUDE publish-manage]

Related topics