我正试图通过调用Jenkins的MSBuild项目将动态确定的产品版本传递给WiX项目。
对于初学者来说,我认为这个问题实际上并不在Jenkins中,因为当我从MS20ild命令提示符运行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
默认值I'在.wixproj文件中设置。
我很确定这不是对MSBuild的实际调用问题,因为用<MSBuild Projects="$(MSBuildProjectDirectory)\ProductName.Installation\ProductName.Installation.wixproj" Properties="ProductVersion=1.2.3.4" />
替换BuildInstaller任务仍然存在同样的问题。
通过搜索我能够找到的东西,我正在做什么应该没问题。但显然不是。关于我遗失或做错的任何想法?
感谢。
答案 0 :(得分:2)
看看:
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:MSIProductVerison=1.2.3.4。或者,您可以设置环境变量TF_BUILD_NUMBER,因为这是TFS最近这样做的方式。