.NET Core - NuGet Packages CI & CD Using GitHub Actions

I always likes to automate the repeatative part of my work. At work, Azure DevOps taking care of the most of the CI & CD. I do maintain a small Class Library project in GitHub which has some helpers and stuffs you know like we reuse on most projects. And is been published to NuGet so that it can be consumed easily.

Recently I added one more project to the same repo which has some common stuff for ASP.NET Core projects. Previously I used to manually upload the .nuget pack file to NuGet since the releases were not that frequent. But now, the number of projects doubled, and sometime we need to deploy both packages since the ASP.NET Core project depends on the other library. So I did automated the whole process using GitHub actions. Here is how I did that,

You can check my repo where you can find the GitHub Actions configuration yml files under the .github/workflows/ directory.

You can see that I am pushing 2 NuGet packages and both have the same version number, which is same as my release tag on GitHub.

During Create NuGet Package stage, initially it was failing with following error

1.dll' to be packed was not found on disk

This was because, in one of the project, it had following Settings in the .csproj file

1<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

Once I removed the above, everything went well. You can see a similar issue posted here.

And the “Publish NuGet Package” job requires an API key from NuGet. You can get the API key from NuGet by logging into your NuGet account, create a new API key.

NuGet API Key

And I stored the key under my repo secrets.

Manage Secrets in GitHub Repository

To manage secrets, on your repo go to the “Settings” tab, under that “Secrets”. There I added a secret with name “nuget_api_key” and we can access those secrets inside actions like ${{ secrets.nuget_api_key }}.

Written by Abhith RajanFollow @AbhithRajan
Abhith Rajan is an aspiring software engineer with more than 7 years of experience and proven successful track record of delivering technology-based products and services.
Buy me a coffee ☕