Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WiX installer remove files on uninstall but not on upgrade

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?

like image 947
Matthew King Avatar asked Jul 20 '10 06:07

Matthew King


2 Answers

Have you tried adding a condition to the RemoveExistingProducts? This is what I would do.

<RemoveExistingProducts After='InstallInitialize'>(NOT UPGRADINGPRODUCTCODE) AND (Installed)</RemoveExistingProducts>
like image 127
Scott Boettger Avatar answered Sep 22 '22 03:09

Scott Boettger


One option would be to switch to a minor update. That has a lot of restrictions so it isn't as easy as it sounds.

like image 39
Rob Mensching Avatar answered Sep 22 '22 03:09

Rob Mensching