Search code examples
wixbundlewix4

WiX4 bootstrapper: Use run time variable in conditional statement


I would like to use a different WIX code depending on the passed command line argument.

<Bundle ... >
  <Variable Name="INSTALL_CONDITION" Value="0" Type="numeric" bal:Overridable="yes" />
  <?ifdef INSTALL_CONDITION?>
     <!-- behaviour #1 -->
  <?else?>
     <!-- behaviour #2 -->
  <?endif?>

In fact my variable INSTALL_CONDITION is not defined at the time of fulfillment of the condition, because all the time I am getting "behaviour #2"

Expected scenario:

  <?if INSTALL_CONDITION = 1?>
     <!-- behaviour #1 -->
  <?else?>
     <!-- behaviour #2 -->
  <?endif?>

Launch command:

.\MyBundle.exe /log log.txt  INSTALL_CONDITION=1

A variable in logs:

Initializing numeric variable 'INSTALL_CONDITION' to value '0'
Setting string variable 'INSTALL_CONDITION' to value '1'
Variable: INSTALL_CONDITION = 1

Solution

  • <?if?> and <?ifdef?> are preprocessor instructions. They are evaluated during compilation and have no effect at runtime. For runtime conditions, look for Condition attributes on, for example, ExePackage.