Nuget Hosted Package

NuGet is the package manager for .NET. It enables developers to create, share, and consume useful .NET libraries. NuGet client tools provide the ability to produce and consume these libraries as “packages”.

Write Code

I used .Net Core 2.2 and build a class library, example code: https://github.com/carlpaton/Common/

Then login at https://www.nuget.org/ with your Microsoft Account.

Create package

  1. Open the .csproj file and add the following properties inside the existing PropertyGroup tag:
1
2
3
4
5
6
7
8
9
10
<PackageId>CarlPaton.Common</PackageId>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Authors>Carl Paton</Authors>
<Company>carlpaton.github.io</Company>
<Description>Common services and magic.</Description>
<Version>1.0.1</Version>
<PackageTags>c#</PackageTags>
<PackageLicenseUrl>https://github.com/carlpaton/Common/blob/master/LICENSE.md</PackageLicenseUrl>
<RepositoryUrl>https://github.com/carlpaton/Common</RepositoryUrl>
<RepositoryType>Github</RepositoryType>
  1. Build a NuGet package, this is the .nupkg file. I ran this from the root of the project C:\Dev\Common>
1
dotnet pack

This generated C:\Dev\Common\Common\bin\Debug\CarlPaton.Common.1.0.0.nupkg

Publish package

  1. Acquire your API key
  2. CD to
1
C:\Dev\Common\Common\bin\Debug
  1. Publish to nuget <3
1
dotnet nuget push CarlPaton.Common.1.0.0.nupkg -k yoursweetkeyhere -s https://api.nuget.org/v3/index.json

Version Information

Add sweet nuget version to your projects README.md on GitHub - NuGet version (CarlPaton.Common)

1
[![NuGet version (CarlPaton.Common)](https://img.shields.io/nuget/v/CarlPaton.Common.svg?style=flat-square)](https://www.nuget.org/packages/CarlPaton.Common/)

References