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.

Reduce disk space consumption in Windows 10

Windows 10 can be quite hungry when it comes to disk space, especially when the system has been used for several years and has been updated several times. In some situations temporary update files are “stuck” in the C:\Windows\WinSXS directory, which at that time can consume up to 17Gb of disk space. Microsoft has published an article describing the process to clean up this directory in more detail. However, this doesn’t always work as described.

I recommend you to do the following:

  1. Download the latest version of System Cleanup, an old but ad-free program that scans the system for temporary files.
  2. Run the Disk Clean-up (as administrator!) and clean-up the system.
  3. Use Dism, the command line deployment tool, the merge existing update images into the current installation using the commands below. This might take several hours to complete. You might need to repeat them once or twice to take effect.
Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
Dism /Online /Cleanup-Image /RestoreHealth
Running System Cleanup, an old but ad-free tool that scans the system for temporary files.
Starting Disk Clean-up as administrator. Make sure you tick all necessary boxes for clean up.

These steps helps helped me to free up roughly 12Gb of storage space on a small little tables that only had a 32Gb drive. Its users can now enjoy using it again for the occasional e-mail and card game, without worrying about a lack of disk space and, as a result, missing important security updates.

Publishing an existing .NET (Core) project to Github

I started working on my home automation project in 2020. I started with a simple backup script that copies the source code to a second hard drive, just in case the primary hard drive fails. When my code base started to grow I extended the script to create a (daily) second copy on OneDrive. From a backup perspective this is working fine, but it does not give me versioning and source control. Luckily, Github exists. Microsoft developed a Github extension for Visual Studio.

Make sure you update your Visual Studio installation before you install the extension. Additionally you need a Github account. After that, publishing an existing project to Github is pretty straightforward. Open the project, click File, Add to Source Control, and Visual Studio will offer you to create a new Github repository.

Add to Source Control in the File menu.

Login to your Github account, and fine a suitable name for your project.

Visual studio will offer you to create a Github repository.

Once you have published the project on Github you need to maintain it. There are three steps required to upload changes to the Github repository:

  1. Pull: pulls the latest version of the repository to the local development machine.
  2. Commit: commits the code changes to a “snapshot” of your project.
  3. Push: pushes the latest snapshot of your project to the repository.