jenkins 通过Jekins服务器上的MSBuild为WiX项目设置产品版本,怎么了?

okxuctiv  于 2023-06-21  发布在  Jenkins
关注(0)|答案(1)|浏览(87)

我试图通过从Jenkins调用MSBuild项目,将产品的动态确定版本传递给WiX项目。
对于初学者来说,我不认为问题实际上是在Jenkins中,因为当从VS2013命令提示符运行MSBuild时,我无法将我试图做的事情工作,并将版本硬编码到我们的MSBuild项目文件中。
MSBuild项目文件设置为从Jenkins运行,参数如下:/p:Configuration=Release /p:Platform="x86" /p:AllowUnsafeBlocks=true
MSBuild项目如下所示:

<?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>

WiX项目文件如下所示:

<?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>

然后在.wxs文件中设置版本我简单地做Version="$(var.BuildVersion)"
然而,当Jenkins在构建项目上调用MSBuild或者我手动键入msbuild build.proj /p:Configuration=Release /p:Platform="x86" /p:AllowUnsafeBlocks=true /p:BUILD_NUMBER=23然后运行创建的.msi文件时,.msi文件中给出的版本始终是我在.wixproj文件中设置的2.0.0.0默认版本。
我很确定问题不是实际调用MSBuild,因为用<MSBuild Projects="$(MSBuildProjectDirectory)\ProductName.Installation\ProductName.Installation.wixproj" Properties="ProductVersion=1.2.3.4" />替换BuildInstaller任务仍然存在同样的问题。
从我所能找到的搜索周围,我所做的应该是好的。但显然不是。你知道我错过了什么或者做错了什么吗?
谢谢

uidvcgyl

uidvcgyl1#

请看:
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)">

调用MSBuild时传递/p:MSIProductVersion=1.2.3.4。或者,您可以设置环境变量TF_BUILD_NUMBER,因为这是TFS目前的做法。

相关问题