Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the product version for a WiX project via MSBuild on a Jekins server. What's wrong here?

I'm trying to pass a dynamically determined version of a product to a WiX project via a call to an MSBuild project from Jenkins.

For starters, I don't think the problem is actually in Jenkins, since I can't get what I'm trying to do to work when running MSBuild from the VS2013 command prompt with a version hardcoded into our MSBuild project file.

The MSBuild project file is set to run from Jenkins with the following parameters: /p:Configuration=Release /p:Platform="x86" /p:AllowUnsafeBlocks=true

The MSBuild project looks as follows:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\.build</MSBuildCommunityTasksPath>
  </PropertyGroup>

  <Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.targets"/>

  <!-- Version Number -->
  <PropertyGroup>
    <Major>0</Major>
    <Minor>9</Minor>
    <Build>1</Build>
    <!--Jenkins sets BUILD_NUMBER -->
    <Revision>$(BUILD_NUMBER)</Revision>
  </PropertyGroup>

  <PropertyGroup>
        <OutputPath>$(MSBuildProjectDirectory)\_LatestBuild\</OutputPath>
  </PropertyGroup>

  <Target Name="Version">
    <Message Text="Version: $(Version)"/>
    <AssemblyInfo CodeLanguage="CS" 
                  OutputFile="$(MSBuildProjectDirectory)\GlobalAssemblyInfo.cs"
                  AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)"
                  AssemblyConfiguration="$(Configuration)"
                  Condition="$(Revision) != '' " />
    <AssemblyInfo CodeLanguage="CS" 
                  OutputFile="$(MSBuildProjectDirectory)\GlobalAssemblyInfo.cs" 
                  AssemblyVersion="$(Major).$(Minor).*"                   
                  AssemblyConfiguration="$(Configuration)"
                  Condition="$(Revision) == '' " />
  </Target>

  <Target Name="AfterBuild">
    <ItemGroup>
      <ZipSourceFiles Include="$(OutputPath)\Installer\**\*.*" Exclude="$(OutputPath)\Installer\**\*.zip;$(OutputPath)\Installer\**\*.wixpdb" />
      <ZipFile Include="ProductName v$(Major).$(Minor).$(Build).$(Revision).zip"/>
    </ItemGroup>
    <Message Text="Zip: $(OutputPath)\*.*"/>
    <Zip Files="@(ZipSourceFiles)" WorkingDirectory="$(OutputPath)\Installer\" ZipFileName="@(ZipFile)" ParallelCompression="false" />
    <Message Text="Copying archive..."/>
    <Copy SourceFiles="@(ZipFile)" DestinationFolder="\\serverName\Projects\Active\ProductName\Builds" />
  </Target>

  <!-- Projects to Build -->
  <ItemGroup>
    <ProjectFiles Include="$(MSBuildProjectDirectory)\**\*.sln">
      <Properties>Configuration=$(Configuration)</Properties>
    </ProjectFiles>
  </ItemGroup>

  <Target Name="Compile" DependsOnTargets="Version">
    <MSBuild Projects="@(ProjectFiles)"  />
  </Target>

  <Target Name="BuildInstaller">
    <MSBuild Projects="$(MSBuildProjectDirectory)\ProductName.Installation\ProductName.Installation.wixproj" Properties="ProductVersion=$(Major).$(Minor).$(Build).$(Revision)" />
  </Target>

  <Target Name="Build">
    <CallTarget Targets="Compile;BuildInstaller;AfterBuild" />
  </Target>

</Project>

The WiX project file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProjectGuid>e5232ce4-4412-4e41-9157-8ab1a36960b0</ProjectGuid>
    <SchemaVersion>2.0</SchemaVersion>
    <OutputName>DicksonWare.Installation</OutputName>
    <OutputType>Package</OutputType>
    <ProductVersion Condition=" '$(ProductVersion)' == '' ">2.0.0.0</ProductVersion>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <OutputPath>..\_LatestBuild\Installer\</OutputPath>
    <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
    <DefineConstants>Debug;BuildVersion=$(ProductVersion)</DefineConstants>
    <SuppressIces>ICE69</SuppressIces>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <OutputPath>..\_LatestBuild\Installer\</OutputPath>
    <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
    <DefineConstants>BuildVersion=$(ProductVersion)</DefineConstants>
    <SuppressIces>ICE69;ICE61</SuppressIces>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Product.wxs" />
  </ItemGroup>
  <ItemGroup>
    <WixExtension Include="WixUIExtension">
      <HintPath>$(WixExtDir)\WixUIExtension.dll</HintPath>
      <Name>WixUIExtension</Name>
    </WixExtension>
  </ItemGroup>
  <Import Project="$(WixTargetsPath)" />
  <!--
  To modify your build process, add your task inside one of the targets below and uncomment it.
  Other similar extension points exist, see Wix.targets.
  -->
  <!--
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

Then in the .wxs file to set the version I simply do Version="$(var.BuildVersion)"

However, when Jenkins calls MSBuild on the build project or I manually type msbuild build.proj /p:Configuration=Release /p:Platform="x86" /p:AllowUnsafeBlocks=true /p:BUILD_NUMBER=23 and then run the .msi file created, the version given in the .msi file is always the 2.0.0.0 default I've set in the .wixproj file.

I'm pretty sure it's not the actual call to MSBuild that's the problem, since replacing the BuildInstaller task with <MSBuild Projects="$(MSBuildProjectDirectory)\ProductName.Installation\ProductName.Installation.wixproj" Properties="ProductVersion=1.2.3.4" /> still has the same problem.

From what I've been able to find by searching around, what I'm doing should be fine. But it's obviously not. Any ideas on what I'm missing or doing wrong?

Thanks.

like image 355
GrantA Avatar asked Sep 28 '22 07:09

GrantA


1 Answers

Take a look at:

http://iswix.codeplex.com/SourceControl/latest#main/Source/Installer/IsWiX/IsWiX.wixproj

<PropertyGroup>
    <!-- If MSIProductVersion not passed in, try to get it fom TFBuild Environments-->
    <MSIProductVersion Condition=" '$(MSIProductVersion)' == '' ">$([System.Text.RegularExpressions.Regex]::Match($(TF_BUILD_BUILDNUMBER), "\d+.\d+.\d+.\d+"))</MSIProductVersion>
    <!-- If we still don't have a value, default to 1.0.0 for developer builds -->
    <MSIProductVersion Condition=" '$(MSIProductVersion)' == '' ">1.0.0</MSIProductVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <DefineConstants>WiXProductVersion=$(MSIProductVersion)</DefineConstants>
</PropertyGroup>

http://iswix.codeplex.com/SourceControl/latest#main/Source/Installer/IsWiX/IsWiX.wxs

<Product Id="*" Name="IsWiX" Language="1033" Version="$(var.WiXProductVersion)"
           Manufacturer="ISWIX LLC" UpgradeCode="$(var.UpgradeCode)">

Pass /p:MSIProductVerison=1.2.3.4 when you call MSBuild. Alternatively you can set the environment variable TF_BUILD_NUMBER as this is how TFS does it these days.

like image 81
Christopher Painter Avatar answered Oct 05 '22 06:10

Christopher Painter