[wix-users] Use PreProcessor variable in BeforeBuild action

Brian Enderle brianke at gmail.com
Fri Nov 6 07:32:15 PST 2015


Thank you for the detailed explanation.  In conjunction with your other
email, I think I understand the build process enough to realize what I am
trying to do isn't possible.

My intent with all this was to avoid making future developers modify the
.wixproj file to update product version, product name, etc.

What I did find is that MSBuild.Community.Tasks has a //Version element
that reads from a text file and can handle auto-incrementing.  In
conjunction with this I am now able to update the Assembly.cs file
automatically at each build and I only need to manually modify the .wixproj
when I first create the WiX project.

Here is how I accomplished this:


-- MySetup.wixproj --

 <!-- Import the AssemblyInfo task -->
  <Import Project="$(WixTargetsPath)" />
  <PropertyGroup>

<MSBuildCommunityTasksPath>$(SolutionDir)\.build</MSBuildCommunityTasksPath>
  </PropertyGroup>
  <Import
Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets" />

  <Target Name="BeforeBuild">

    <Version VersionFile="version.txt" RevisionType="Increment">
      <Output TaskParameter="Major" PropertyName="Major" />
      <Output TaskParameter="Minor" PropertyName="Minor" />
      <Output TaskParameter="Build" PropertyName="Build" />
      <Output TaskParameter="Revision" PropertyName="Revision" />
    </Version>

    <!-- Update Utilities Assembly.cs for this product (change GUID for
each new product) -->
    <AssemblyInfo
OutputFile="$(SolutionDir)\MyProject\Properties\AssemblyInfo.cs"
CodeLanguage="CS" AssemblyTitle="My Project" AssemblyProduct="My Project"
AssemblyDescription="My Project" AssemblyConfiguration=""
AssemblyCompany="My Company" AssemblyCopyright="©My Company 2015"
AssemblyTrademark="" AssemblyCulture="" ComVisible="false"
AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)"
Guid="******-44BA-*********" />
  </Target>


Running this the first time creates the version.txt file which I included
in my WiX project and now when I want to release a new version I simply
update the Major/Minor/Build number(s) and the "Increment" auto-increments
the Revision.



Brian

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

On Fri, Nov 6, 2015 at 9:30 AM, Phill Hogland <phill.hogland at rimage.com>
wrote:

> 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/
>
> ____________________________________________________________________
> WiX Toolset Users Mailing List provided by FireGiant
> http://www.firegiant.com/
>


More information about the wix-users mailing list