Visual Studio: How to automatically uninstall previous installed version?

Older versions are uninstalled automatically if you increase your Product Version and change the Package Code. This needs to be done each time you modify the setup project and build a new package.

If you keep the same version and Product Code, older builds cannot be uninstalled automatically. They are detected by Windows Installer before your new package is actually launched. So you need to uninstall them manually.


I struggled with this for a long time but it is very simple.

  1. Go to manage VS Extensions (VS2019) and install 'Microsoft Visual Studio Installer Project' v0.9.9
  2. Right click on your installer project and go to properties. Keep the UpgradeCode variable in the properties window the same for different versions of the same product.
  3. Change your ProductCode variable between different builds.
  4. Now when you install the product with the same UpgradeCode already on the system, the installer will upgrade your existing product and you will only have one program in the Add/Remove window.

The answer is not to use the Visual Studio setup project that's already integrated. I'm having the exact same problem: it won't remove previous versions even though I up the version, set it to remove previous version, check for previous version and rebuild, I can install but the files aren't updated. There are some good tools for this out there, check out bitrock, inno setup or wix.

Also Visual Studio 2010 was the last version with setup project support. It's not included in 2012.


In my case I found out that the setup project wasn't part of the configuration manager. Therefore, it wasn't rebuld on solution rebuilds and setup file with the new version and ProductCode wasn't generated.

The solution is simply to right click on the setup project and click rebuild.

Hope this help to future readers :)