How to publish your own Nuget Package - Day 12 - 24 days of "Front-end Development with ASP.NET Core, Angular, and Bootstrap"

With package managers you consume libraries but eventually you will end up releasing yours for others to use, either to the community or as shared among co-workers. Today we look into how to do it with Nuget and .NET Core.

Doing a Nuget package was a bit convoluted with the traditional .NET Framework, but with .NET Core it's very easy.

Add metadata

After having developed the application, just add to your .csproj file the metadata needed (no need for a specific .nuspec).

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <PackageId>Wrox.Book</PackageId>
    <PackageVersion>1.0.0</PackageVersion>
    <Authors>Simone Chiaretta</Authors>
    <Description>Show the title of the book</Description>
    <PackageReleaseNotes>First release</PackageReleaseNotes>
    <Copyright>Copyright 2017 (c) Simone Chiaretta</Copyright>
    <PackageTags>book title Wrox</PackageTags>
    <PackageProjectUrl>http://example.com/Wrox.Book/</PackageProjectUrl>
    <PackageIconUrl>http://example.com/Wrox.Book/32x32icon.png</PackageIconUrl>
    <PackageLicenseUrl>http://example.com/Wrox.Book/mylicense.html</PackageLicenseUrl>
  </PropertyGroup>
</Project>

Create the package

Now just go to the root of the project (where the .csproj is) and type dotnet pack -c Release. This will build the project and create a nuget package file, saved in bin\Release.

If you now open the file with the Nuget Package Explorer you'll see the content of the file

Nuget Package Explorer

Publish the package

Now you can just either copy the file to a local repository or publish it to the Nuget public repository. To do so:

  • Download the NuGet command line utility (the dotnet cli is not enough here). You can install it via Nuget as well: Install-Package NuGet.CommandLine
  • Create an account on the NuGet.org gallery (if you don't have one)
  • Set your API-KEY: nuget setApiKey Your-API-Key
  • Publish the package: nuget push YourPackage.nupkg

This topic is covered more in details, together with how to develop packages for NPM and bower, on my upcoming book "Front-end Development with ASP.NET Core, Angular, and Bootstrap". If want to read more extracts of the book, come and visit my blog again tomorrow.