visual-studio-2013 - 通过 Jekins 服务器上的 MSBuild 为 WiX 项目设置产品版本。这里有什么问题?

标签 visual-studio-2013 jenkins msbuild wix

我正在尝试通过从 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 文件中给出的版本始终是 2.0.0.0我在 .wixproj 文件中设置了默认值。

我很确定问题不是对 MSBuild 的实际调用,因为用 <MSBuild Projects="$(MSBuildProjectDirectory)\ProductName.Installation\ProductName.Installation.wixproj" Properties="ProductVersion=1.2.3.4" /> 替换了 BuildInstaller 任务。仍然有同样的问题。

从我通过四处寻找能够找到的东西来看,我在做什么应该没问题。但显然不是。关于我缺少什么或做错了什么的任何想法?

谢谢。

最佳答案

看一眼:
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)">
通行证/p:MSIProductVerison=1.2.3.4当您调用 MSBuild 时。或者,您可以设置环境变量 TF_BUILD_NUMBER,因为这就是 TFS 现在的做法。

关于visual-studio-2013 - 通过 Jekins 服务器上的 MSBuild 为 WiX 项目设置产品版本。这里有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29608950/

相关文章:

c# - Visual Studio 2013 深色主题折叠文本颜色几乎不可见

visual-studio-2013 - 设置 SQLProj Pre/PostDeploy 脚本以失败构建

java - Jenkins - mvn 未找到

ssl - 来自 Windows AD CS 的 Jenkins SSL 证书

c++ - 使用 .Net 2.0 C++ 项目的 Build box 需要 VS.Net 2005 吗?

javascript - 在 VS2013 中保持 javascript 函数折叠

java - 服务器拒绝连接 : None of the protocols were accepted

asp.net - MSBuild 脚本和 VS2010 发布应用 Web.config 转换

.net - 如何在 Rider 中触发文件更改的设计时构建?

c++ - 具有成员函数的 VS2013 std::function