[wix-users] Use PreProcessor variable in BeforeBuild action

Phill Hogland phill.hogland at rimage.com
Fri Nov 6 06:30:34 PST 2015


The following code that you posted are snippets from a wixproj file, which uses the MSBuild syntax, so you cannot use Wix schema elements, like WixVariable directly in the MSBuild script.  The WixVariable element is interpereted by candle.exe and light.exe/lit.exe, and not by MSBuild.

In your wixproj file do something like this:
  <PropertyGroup >
     <!-- MSBuild properties which are the same for all configurations.   I find it a good idea to prepend my custom MSBuild properties, to make sure that they are unique, so here I use "My...." but it could be an abbreviation for the company.  -->
     <MyProductVersion>BuildVersion2=2.2.2</ MyProductVersion >
  </PropertyGroup>
 <!-- Now do each of the standard configuration blocks.-->
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     <OutputPath>bin\</OutputPath>
     <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
     <DefineConstants>Debug;BuildVersion=1.1.1</DefineConstants>
     <WixVariables>BuildVersion2=2.2.2</WixVariables>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     <OutputPath>bin\</OutputPath>
     <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
     <DefineConstants>BuildVersion=1.1.1</DefineConstants>
     <WixVariables>BuildVersion=2.2.2</WixVariables>
  </PropertyGroup>
<!-- After all of the configuration PropertyGroups, set MSBuild properties and Wix tool commands-->
  <PropertyGroup >
    <CompilerAdditionalOptions>
      $(CompilerAdditionalOptions)
       <!-- The above line allows you to define CompilerAddionalOptions in other .targets files and use the MSBuild Import command prior to this point in this file. -->
      <!-- In the following line $(MyProductVersion) is an MSBuild Property that is above this pointin this file, or was MSBuild Imported earlier in this file.   The -d tells the wix pre-processor (candle.exe) to create the pre-processor variable MyProductVersionPreVar, which you can then use in your wxs files using the syntax $(var.MyProductVersionPreVar) -->
      -d MyProductVersionPreVar ="$( MyProductVersion)"
    </CompilerAdditionalOptions>
    <LinkerAdditionalOptions>
      $(LinkerAdditionalOptions)
      -nologo
      -b ImgServer="\\halo\CDSet\Build_Input_Area\9.1_DIST_RSS\Model\programfiles\Rimage\Imaging Server\\"
      -b STATIC_ImgServer="\\halo\CDSet\Build_Input_Area\9.1_DIST_RSS\Model\STATIC\programfiles\Rimage\Imaging Server\\"
    </LinkerAdditionalOptions>  </PropertyGroup>

So once you create that pre-processor variable in your .wixproj file, you then use it in a wxs file as a pre-processor variable, (AND do not define a variable of the same name in a wxi file, as it is already defined by the -d command.)

For an MSI package .wxs project you can use it in the Product element like this
 <Product Version="$(var.MyroductVersion)" ............. />

<!--  IF you are importing a WIXLIB which also needs this information, then you would create a WixVariable to pass down to the WIXLIB -->
<WixVariable Id="MyAppRegKey" Value="SOFTWARE\Company\App_$(var.MyProductVersion)"
</Product>

In the WIXLIB you might have something like this that uses the WixVariable
    <Component ..........">
      <RegistryValue Root="HKMU" Key="!(wix.MyAppRegKey)" Name="something" Value="some data" Type="string" KeyPath="yes" />
    </Component>

For a Bundle element  if the above wixproj was for a bootstrapper project 

 <Bundle Version="$(var.MyroductVersion)" ....>

  <!-- IF you want to pass this value to a bootstrapper application then use a Burn Engine Variable.  In the case of the product version it is already passed into the BA as ProductVersion, but this example is so that you can do this for some other purpose which is not obvious.  -->
  <Variable Name="MyProductVersionEngVar" Type='string' Value="$(var.MyroductVersion)" Persisted='yes' bal:Overridable='yes' />

  <!-- IF you also need to pass this info down to a WIXLIB, then use a WixVariable as described above. -->

</Bundle>




-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of Brian Enderle
Sent: Friday, November 06, 2015 6:59 AM
To: WiX Users <wix-users at lists.wixtoolset.org>
Subject: [wix-users] Use PreProcessor variable in BeforeBuild action

I have the following defined in my wixproj file:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86'
">
     <OutputPath>bin\</OutputPath>
     <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
     <DefineConstants>Debug;BuildVersion=1.1.1</DefineConstants>
     <WixVariables>BuildVersion2=2.2.2</WixVariables>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     <OutputPath>bin\</OutputPath>
     <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
     <DefineConstants>BuildVersion=1.1.1</DefineConstants>
     <WixVariables>BuildVersion=2.2.2</WixVariables>
  </PropertyGroup>


Is there a way to use either 'BuildVersion' or 'BuildVersion2' in a BeforeBuild action?  Something like:

   <AssemblyInfo AssemblyVersion="$(var.BuildVersion)" />

or

   <AssemblyInfo AssemblyVersion="$(var.BuildVersion2)" />


TIA

Brian

If you can't explain it simply, you don't understand it well enough.  - Albert Einstein

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/


More information about the wix-users mailing list