Using nuget.exe in Visual Studio 2017

In earlier versions of Visual Studio before 2017 I used to create nuget packages by adding a new post-build event that deleted the old nupkg file and created a new package by invoking nuget.exe:

nuget pack "$(ProjectPath)"

This suddenly stopped working in Visual Studio 2017 – I got an error 9009 on this line, meaning that nuget.exe was not found by Visual Studio 2017. So I obtained the latest copy of nuget.exe and put it in C:\Windows\System32, executing it on the Windows console to make sure it was in the Path. It worked. But guess what? The error was still there in Visual Studio and the Visual Studio nuget console.

To make a long story short: As Visual Studio 2017 is still 32-bit, you need to place nuget.exe in C:\Windows\System32\SysWOW64 to make it work…