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
- Open the
.csproj
file and add the following properties inside the existingPropertyGroup
tag:
1 | <PackageId>CarlPaton.Common</PackageId> |
- Build a NuGet package, this is the
.nupkg
file. I ran this from the root of the projectC:\Dev\Common>
1 | dotnet pack |
This generated C:\Dev\Common\Common\bin\Debug\CarlPaton.Common.1.0.0.nupkg
Publish package
- Acquire your API key
- CD to
1 | C:\Dev\Common\Common\bin\Debug |
- 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 -
1 | [![NuGet version (CarlPaton.Common)](https://img.shields.io/nuget/v/CarlPaton.Common.svg?style=flat-square)](https://www.nuget.org/packages/CarlPaton.Common/) |