GitHub Actions — Automate Nuget Package Deployments

As soon as I signed up for GitHub Actions beta, I decided to use it to automate Nuget package deployment. After some tinkering, I managed to succeed while learning some important tips and caveats.
🔎 What do I need?
- Nuget Account
- GitHub Actions. You can sign up here if you haven’t already.
- .Net Core 2.0 or newer
🔥 Enough talk, give us the sauce
Get the API Key from Nuget. Make sure to save the key in a secured location as you won’t be able to retrieve it later.
Next step is to go to GitHub > {repository}> setting > secrets and add your api key there.

Add the following snippet in your class library .csproj file.

This helps with debugging experience of your nuget packages.
Create your YAML file in .github > workflows > {file}.yml and push it to the GitHub. The folder structure is important and it must be in root of your repository.

Here I am referring to my secret using ${{ secrets.NUGET_DEPLOY_KEY }} which fetches the API key from GitHub secrets.
Push it to GitHub, go to Actions tab in your repository and watch your code get built, tested and deployed.
✅ Some bits to note
Do make sure to update the version of package in your csproj file else Nuget will not let us upload the package and our pipeline will fail.
If you don’t have the aforementioned code snippet in your csproj file, your package will be deployed but the GitHub Actions Pipeline will fail because Nuget won’t be able to find the symbols (.snupkg) file. To avoid this, update the YAML file with following code snippet.

