Publishing .NET Core NuGet Packages (tl;dr)

2017-01-29

For a thorough exploration of this topic, head over to the detailed version of this post

Prerequisites

Creating a Class Library

1
2
3
4
5
mkdir MyFancyPackage
cd MyFancyPackage
dotnet new -t Lib # creates class library project in current dir
dotnet restore # restores NuGet packages
dotnet build # builds library

Adding Package Metadata

Modify your csproj to look like this, replacing any {} placeholders:

1
2
3
4
5
6
7
8
9
10
11
12
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<Version>0.0.1</Version>
<AssemblyName>{YourGitHubHandle}.MyFancyPackage</AssemblyName>
<PackageId>{YourGitHubHandle}.MyFancyPackage</PackageId>
<Description>Sample package for .NET Core NuGets</Description>
<Authors>{yourName}</Authors>
<PackageProjectUrl>{yourGithubRepoUrl}</PackageProjectUrl>
<PackageTags>sample dotnetcore nuget dotnetstandard</PackageTags>
</PropertyGroup>
</Project>

Build a Package From Your Library

1
dotnet pack -c Release # bundles your library as a .nupkg in bin/release

Publish Your Package

Replace with the API key on your nuget.org account page:

1
nuget push bin/Release/<YOUR_HANDLE>.MyFancyPackage.0.0.1.nupkg <API_KEY> -Source https://www.nuget.org/api/v2/package

Done!

If you want to see your package in action, follow these steps in the detailed post.