I try to create an MSI bundle that will uninstall the program if it's already installed. So, the same MSI file is used for installing and uninstalling the program, but it will install on the first run, uninstall on the second, and so on.
MSI file is in the same solution as the program and is built on CI server on each commit, therefore every bundle has a newly generated unique BundleId. Everything is ok when I install/uninstall from the same MSI file. Bad things begin when I run different MSI files, for example I install from MSI built on commit #1 and then run the MSI build on commit #2. In that case the program doesn't get uninstalled because MSI #1 and MSI #2 have the same UpgradeCode (UC), but different BundleId's. So, WIX thinks that I have product #1 and product #2 installed in my system which both depend on the same package UC. When I run MSI #2 it uninstalls itself first, then tries to uninstall dependency package UC, but detects that product #1 still uses it and so uninstaller fails to uninstall my program.
This is a snippet from my log:
[1D5BC:3CD4][2015-04-03T14:59:58]w327: Will not uninstall package: MSIMyApp, found dependents: 1
[1D5BC:3CD4][2015-04-03T14:59:58]w328: Found dependent: {bdb84fac-4961-438f-ae94-7e586840a5f1}, name: MyApp
When I run #2 for the second time, it detects that package is still installed and runs uninstall again!
I found a workaround which is to manually delete from registry everything that has my UpgradeCode in BundleUpgradeCode at address
HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\
But unfortunately this solution is not acceptable because it has to be entirely automatic. What am I doing wrong with WIX?