tags:

views:

1188

answers:

3
+6  Q: 

Wix major upgrade

How do I use WIX to prevent overwriting a config file during a 'Major Upgrade'?

I want the file to be installed on the initial install, removed on uninstall, and left unchanged on a 'Major Upgrade'.

Thanks

+8  A: 

The most straight forward way would be to schedule your RemoveExistingProducts after InstallExecute or InstallFinalize. That way the config file is not removed and then installed again (like if you schedule before InstallInitialize). Of course, scheduling RemoveExistingProduct so late means you need to be very careful about your Component Rules.

My personal favorite is to treat configuration like "user data" and not have the installtouch it at all. You ship defaults with the application but any changes are made by the user in their private user profile. Gets you out of all kinds of nasty migration problems that just aren't solved well during setup.

Rob Mensching
+1 for the user-profile, we use major version in the path as well (e.g. %AppData%\Manufacturer\Product\1.0\...) so that we can alter the config format with a major release and let the user choose to weather to upgrade/migrate their config.
sascha
Rob can you explain what you mean by be careful about your Component Rules?
KevM
A: 

You can use the UPGRADINGPRODUCTCODE property to check if you are upgrading. We use this to determine if we should run our 'clean up' custom action:

<Custom Action="" After="CleanUpFiles">
  <![CDATA[REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE]]>
</Custom>

I do agree with Rob, in that the config is user data, stored in their AppData folders, and never created by the MSI. Instead it is set do a default value (which we store as a default config in the programs files), and copied over by the app itself. But we don't want to leave these things cluttering a user's machine if they want to uninstall our product, so we made a CleanUpFiles that searches the HD for any garbage left behind.

csexton
I'm using this method to remove license data and other registry information that should be preserved across a major upgrade. However for on-disk configuration files these are stored in the user-profile and so still remain if the user does uninstall/reinstall.
sascha
+2  A: 

Do you ever want it overwritten? If not in cases like this I assign the config files to their own components and mark them as Never Overwrite. This way upgrades will not overwrite the file but uninstalls will remove it.

e.g.

<Component Id="myComp" Guid="myguid" NeverOverwrite="yes">
mjmarsh