[wix-users] Use PreProcessor variable in BeforeBuild action

Phill Hogland phill.hogland at rimage.com
Fri Nov 6 09:58:12 PST 2015


I certainly agree with the goal.  My approach is similar, in that I created a MSBuild ITask project in which I implement my business rules for incrementing the version, and is called in the wixproj prior to beginning the build.  Incrementing the fourth part of the version is fine for the bundle project.  That is what I do for my bundles (and what the WixBA does).  I set Major. Minor. ServiceRevision when the project's 'release cycle' tree is created, and then the forth portion of the version is increment for each build automatically so that it can never be stagnate or declining.  After the bundle is released, if I want to ship a service update or patch in the same bundle chain, I just increment third portion and Burn treats that as a 'MajorUpgrade' from the bundle's perspective replacing the old bundle.

For a MSI WiX "setup" project one needs to increment the third part of the version (Major.Minor.Build) as the last (forth) part is ignored when used in Product/@Version.   The forth past of a version with respect of a versioned file in a MSI package is not ignored.

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

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\programfil
> es\Rimage\Imaging
> Server\\"
>       -b
> STATIC_ImgServer="\\halo\CDSet\Build_Input_Area\9.1_DIST_RSS\Model\STA
> TIC\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/
>

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


More information about the wix-users mailing list