Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wix conditionals and preprocessor variables

Tags:

wix

I want to change the value of a Wix variable depending on whether a value is defined or otherwise. In my wixproj I have:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'TFS Live|x86' ">
    <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj\$(Platform)\$(Configuration)\</IntermediateOutputPath>
    <WixVariables>LIVE</WixVariables>
    <DefineConstants>LIVE</DefineConstants>
  </PropertyGroup>

...and in my wxs I have:

<?ifdef LIVE ?>
<?define binaryPath = "C:\Builds\5\IT Aerodynamics\RBT.TestSpec.LiveRelease\Binaries" ?>
<?else?>
<?define binaryPath = "C:\Builds\5\IT Aerodynamics\RBT.TestSpec.CI\Binaries" ?>
<?endif?>

...but when I build the appropriate configuration, the ifdef never fires. I always get the second value for binaryPath. Any suggestions as to what I'm doing wrong?

like image 465
TarkaDaal Avatar asked Aug 02 '26 23:08

TarkaDaal


2 Answers

That code works for me. One thing to check is that you don't have another DefineConstants MSBuild Property later in the .wixproj that doesn't look like:

<DefineConstants>$(DefineConstants);OtherVars=Value</DefineConstants>

The default .wixproj template creates projects where the Debug preprocessor variable is defined like:

<DefineConstants>Debug</DefineConstants>

And that will overwrite DefineConstants defined higher in the project for debug builds. Otherwise, everything looks fine.

like image 171
Rob Mensching Avatar answered Aug 05 '26 20:08

Rob Mensching


One more thing, in addition to the @RobMensching answer.

If you build your solution using command line and msbuild, and if you define your DefineConstants in that build command, all your defines in projects will be overridden with those defined in command line:

msbuild Your.sln /t:Build
        /p:Configuration=TFSLive
        /p:Platform=x86
        /p:DefineConstants=Your;Defines;Here
like image 36
stukselbax Avatar answered Aug 05 '26 20:08

stukselbax