Automatically push .NET libraries on NuGet

Getting the source code of my home automation project on Github was a first step. Now, I’m ready to post some components on NuGet as well. This makes it easier to manage the packages and reduces the dependencies between my Visual Studio projects.

I ran into a challenge though: how could I easily upload my projects to NuGet without having to use the command line? Luckily, Visual Studio has something called Post-build event command line.

Post-build event command line; you can find this in the properties / build events tab of your project.

The command put into this block is executed after finishing the build. The only thing you need to do manually is change the package version, otherwise NuGet will rightfully decline the push (the version already exists).

You need to manually update the package version for NuGet to accept the push.

Depending on your directory and project structure you should be able to get the command below up and running. You can easily test this in the Command Prompt, just make sure you browse to the right target directory.

cd bin\Debug && dotnet nuget push *.nupkg -k xxx -s --skip-duplicate

Of course, you should replace the xxx with the NuGet API key.