ninjaria
ninjaria

Reputation: 3

How to conditionally run the Upgrade element in WiX based on environment variable

Is there are way I can get the Upgrade element to only run when a certain environment variable is not set?

Otherwise, if the environment variable is detected, the installer should install the new software side by side with the existing one.

Since Upgrade doesn't take the Condition element, I tried to put it in a Fragment like this:

<Fragment>
  <Upgrade Id="$(var.Guid7)">
    <UpgradeVersion Minimum="$(var.Version).0" Maximum="$(var.Version).2" IncludeMinimum="yes" IncludeMaximum="no" Property="PREVIOUSREVISIONINSTALLED" />
  </Upgrade>
  <ComponentGroup Id="FakeComponent" />
</Fragment>

Then calls it from Product using a Feature:

<Feature
    Id="ConditionalUpdate"
    Title="Upgrade"
    Absent="allow" AllowAdvertise="no"
    Level="1" >
  <Condition Level="0" ><![CDATA[%CERTAIN_VARIALBE]]></Condition>
  <ComponentGroupRef Id="FakeComponent" />
</Feature>

However this seems to trigger the Upgrade code everytime so it always update, no matter whether the environment variable is defined or not.

Any idea on how to solve this issue? Any help is appreciated.

Upvotes: 0

Views: 169

Answers (1)

PhilDW
PhilDW

Reputation: 20780

This is essentially the same question as this one:

How to let the user choose between upgrade or full install?

except that you decide based on the environment variable. In your case you can condition the RemoveExistingProducts actions on %ENV which is a standard Windows Installer condition using environment variables:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa368012(v=vs.85).aspx

but without knowing the exact check I can't quote the exact condition you would need.

The transforms solution might be appropriate, it's difficult say without knowing the entire environment (maybe you are already using transforms for something else).

Upvotes: 1

Related Questions