views:

92

answers:

2

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?

A: 

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.

Rob Mensching
A: 

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

<RemoveExistingProducts After='InstallInitialize'>(NOT UPGRADINGPRODUCTCODE) AND (Installed)</RemoveExistingProducts>
Scott Boettger
This seems like what I want, but of course it means that the previous version isn't removed on upgrading. For example, I end up with multiple entries for my application in the 'Add or Remove Programs' control panel. Any workaround?
Joviee
You could try the remove existing product to After InstallFinalize. This would remove any changed files and registry settings but keep what you didn't. IT could also have to do with you ProductID or version. The OS probably thinks it's a different program entirely.
Scott Boettger

related questions