简体   繁体   English

TFS 2013-从预构建PowerShell脚本更新MSBuild参数

[英]TFS 2013 - Update MSBuild Parameters from pre-build PowerShell script

I have recently upgraded from TFS 2012 to TFS 2013 and am trying to use the new template (TfvcTemplate.12.xaml). 我最近已从TFS 2012升级到TFS 2013,并尝试使用新模板(TfvcTemplate.12.xaml)。 I need to set the version numbers of my .NET applications and WiX installers as part of this process. 在此过程中,我需要设置.NET应用程序和WiX安装程序的版本号。 In my TFS 2012 process I customised the build template using TFS Community Build Extensions to do the following: 在TFS 2012流程中,我使用TFS社区构建扩展自定义了构建模板,以执行以下操作:

  1. Generate a version number. 生成版本号。 The Major and Minor version numbers are static, the release number is the number of days since 2014-11-25, the build number is the number of times the build definition has run today. 主要和次要版本号是静态的,发布号是自2014-11-25以来的天数,内部版本号是今天内部定义运行的次数。

  2. Update all AssemblyInfo.cs files with the new version number 使用新版本号更新所有AssemblyInfo.cs文件

  3. Update the MsBuildArguments argument to pass the version as a parameter. 更新MsBuildArguments参数以将版本作为参数传递。 This is so that I can set the version number in my WiX installers. 这样便可以在WiX安装程序中设置版本号。

Before I resort to customising the build template again I would like to try to achieve the above using a Pre-build PowerShell script. 在再次求助于自定义构建模板之前,我想尝试使用预构建PowerShell脚本实现以上目标。

Items 1 and 2 were easy in PowerShell but I am stuck with the third requirement. 在PowerShell中,第1项和第2项很容易,但我坚持第三个要求。 Is it possible for the Pre-build PowerShell script to update the MSBuildArguments? 预构建PowerShell脚本是否可以更新MSBuildArguments?

I think there is a simpler way to do this. 我认为有一种更简单的方法可以做到这一点。 This is what we did. 这就是我们所做的。

Created an include file called Version.wsi. 创建了一个名为Version.wsi的包含文件。 The file contains these 4 lines: 该文件包含以下4行:

<?xml version="1.0" encoding="utf-8"?>
<Include>
  <?define CurrVersion="1.0.0.0" ?>
</Include>

In our wxs file, right after the line 在我们的wxs文件中,

<Wix xmlns:util="http://schemas.microsoft.com/wix/UtilExtension" xmlns="http://schemas.microsoft.com/wix/2006/wi" >

add the following: 添加以下内容:

  <?include Version.wxi ?>

In your wxs file use the variable $(var.CurrVersion) where you currently specify your version. 在wxs文件中,使用变量$(var.CurrVersion)在当前指定版本的位置。

Now all you need to include in your powershell script is some code to modify the wxi file with the correct version number. 现在,您需要在powershell脚本中包括的只是一些代码,可以使用正确的版本号修改wxi文件。 This is how I do it: 这是我的方法:

function UpdateVersion($newVersion)
{
    $wxiFile = gci "$Somedir\Version.wxi"
    #clear the read-only bit just in case
    Set-ItemProperty $wxiFile -name IsReadOnly -value $false -Force

    $newContent = $content -replace "1.0.0", $prodVersion
    Set-Content -Path $wxiFile -Value $newContent
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM