Tuesday, 6 January 2009

LaunchConditions, FindRelatedProducts and Downgrades

Quite a long time ago I had a problem with my WiX installs when tried to detect that a newer version was installed (Upgrade code failing for silent installs). I thought the solution was to use a custom action to detect the newer version but I have finally realised what the problem was.

To recap: my install worked fine if it was running with a UI but if I ran it silently so that the InstallUISequence sequence didn't run the newer version launch condition wasn't run. This is the code I had:

<!-- Upgrade settings -->
<Upgrade Id="$(var.UpgradeCode)">
<UpgradeVersion Minimum="$(var.Version)" OnlyDetect="yes" Property="NEWERVERSIONDETECTED" />
<UpgradeVersion Minimum="0.0.0" Maximum="$(var.Version)"
IncludeMinimum="yes" IncludeMaximum="no" Property="OLDERVERSIONBEINGUPGRADED"/>
</Upgrade>

<Condition Message="A later version of [ProductName] is already installed.">NOT NEWERVERSIONDETECTED</Condition>

This worked with a UI sequence because the default sequence for LaunchConditions is 100 and FindRelatedProducts is 200. From this it is clear that the launch condition won't trigger until FindRelatedProducts has run and when there is a UI sequence the order would be LaunchConditions, FindRelatedProducts then LaunchConditions again in the execute sequence and on this second run it would trigger the launch condition. If running silently only LaunchConditions is followed by FindRelatedProducts and hence the launch condition will never trigger.

So the solution is quite simple, ensure FindRelatedProducts runs before LaunchConditions e.g.:

<InstallExecuteSequence>
<FindRelatedProducts Before="LaunchConditions" />
</InstallExecuteSequence>
<InstallUISequence>
<FindRelatedProducts Before="LaunchConditions" />
</InstallUISequence>

Edit 02/03/09: As of WiX version 3.0.5027.0 the default is for FindRelatedProducts to run before LaunchConditions so this code is not required.

2 comments:

Anonymous said...

Note that this works for Wix 3 only. On Wix 2 you have to do either:

<LaunchConditions After="FindRelatedProducts" />

Or
<FindRelatedProducts Sequence="50" />

As the FindRelatedProducts element has no before/after available.

Anonymous said...
This comment has been removed by a blog administrator.