views:

249

answers:

2

I'm working on the upgrade feature for my WiX-based installer.

As part of the instalation, we are installing a web.config file and then using a custom action to update the connection strings inside the file.

But this causes a problem when we run our upgrade. We would like to have the RemoveExistingProducts scheduled for after InstallFinalize since this is most efficient in terms of not removing and reinstalling files that have not changed. But this leaves the original web.config file in place at the time when Windows Installer is trying to determine whether it should update it or not. Since it's last modified date is more recent than its creation date, Windows Installer decides not to update it (see versioning rules that Windows Installer uses). But we need it to be updated.

One obvious solution is to change the scheduling of RemoveExistingProducts to after InstallValidate - but this is inefficient, and also, I don't think it would give us the opportunity to migrate settings from existing files, should we need to do that.

Any other ideas?

A: 

Only iffy ones. You could remove the specific file early with a custom action, but be sure to condition this right! Or you could specify a version for the file so upgrade rules will treat it like replacing a non-versioned file with a versioned one, but then patches can get antsy about having the wrong version of this file.

Michael Urman
+2  A: 

There are many ways - none are ideal.

1: You can use a companion file to force update of the file in question. Provided the companion file specified always gets updated, this may be the way to go. Essentially this means that you link the non-versioned file to the version update logic of its companion file (files are updated together). I have never used this in WIX, but I think it's as easy as adding the CompanionFile attribute to a File element and point to the ID of the file you want to "version follow".

2: You can use a custom action to delete the file before file costing (or better yet, rename it to a backup format). The problem is that if the setup fails the file will be missing. If you rename the file instead of deleting you can put it back in case the setup fails via a rollback custom action. Sometimes I use the RemoveFile table to remove files on install, but depending on the sequencing specified in InstallExecuteSequence this may not work (deletion must happen before msi does file costing).

3: Then there is the sledgehammer approach: set REINSTALLMODE = amus to force overwrite all files regardless of version. I shouldn't even mention this since it is horribly dangerous (you can end up overwriting system files). PLEASE never EVER do this on production systems. I use it sometimes on dev systems to save time - and then it works ok. But I repeat : NEVER in production. It might seem quick and easy, but trust me, it's NEVER safe.

Glytzhkof
http://wix.mindcapers.com/wiki/Companion_File for a quick sample of how to implement the companion file approach in WIX.
Glytzhkof
The Companion file approach looks like it might be the way to go. Thanks for the link. Thanks also for the warning about REINSTALLMODE: I had read about that, and was considering it - no longer!
Samuel Jack

related questions