I have a program that installs with a WiX installer.
The program itself creates a number of files in the [CommonAppDataFolder]\[MyAppName]\ directory. These files all have the same extension (lets call it .dat).
On upgrading, I want to retain these files.
On uninstalling, I want to remove these files.
I am currently deleting the files as so:
<Directory Id='CommonAppDataFolder'>
<Directory Id='MyCommonAppDataFolder' Name='MyAppName'>
<Component Id='RemoveFilesComponent' Guid='71cb0cd8-8459-4a8f-89b7-f00977aa7b70'>
<RemoveFile Id='RemoveFiles' Name='*.dat' On='uninstall'/>
</Component>
</Directory>
</Directory>
And I have this to facilitate upgrades:
<InstallExecuteSequence>
<RemoveExistingProducts After='InstallInitialize'/>
</InstallExecuteSequence>
Now, when I uninstall, the .dat files are removed correctly.
However, when I upgrade, the .dat files are also removed. I guess because an upgrade is performing an uninstall on the previous version.
Am I approaching this problem correctly? How can I retain the files on upgrade, while removing them on uninstall?
Have you tried adding a condition to the RemoveExistingProducts? This is what I would do.
<RemoveExistingProducts After='InstallInitialize'>(NOT UPGRADINGPRODUCTCODE) AND (Installed)</RemoveExistingProducts>