TFS 2015 构建带有提交 ID 的 vNext 更新文件版本

TFS 2015 build vNext update file version with commit id

你知道如何将提交 ID 注入文件版本吗,所以每个程序集都会像 2.0.6565.0 这样的版本,其中 6565 与 TFS 中的 C6565 提交 ID 相关?

看起来有些强大 shell 需要脚本。

如果您的问题与您的另一个 post 相似,想要获取在 gated check-in 期间未签入的变更集 ID,那么在单个构建。

如果您不使用门控签入,则可以在 powershell 脚本中使用 $Env:BUILD_SOURCEVERSION 来设置 AssemblyVersion。下面的网址已经有脚本了,大家可以参考一下:

https://github.com/wulfland/ScriptRepository/blob/master/TFSBuild/TFSBuild/AssemblyVersion/Set-AssemblyVersion/Set-AssemblyVersion.ps1

最后,我基于 this post 创建了自己的 PS 脚本。 所有包含程序集信息的文件中的想法更新版本

$CommitId = ([string]$env:BUILD_SOURCEVERSION) -replace "[^0-9]+", ""
$AllVersionFiles = Get-ChildItem $SourceDir AssemblyInfo.cs -recurse
$regexToFindVersion = "Version\(""([0-9]+)\.([0-9]+).+"""

foreach ($file in $AllVersionFiles) 
{
    Write-Host "Processing " $file.FullName

    (Get-Content $file.FullName) |
    %{$_ -replace $regexToFindVersion, ('Version("..0.' + $CommitId + '"') } |
    Set-Content $file.FullName -Force
}

可以找到完整的脚本 here

脚本必须在构建项目之前放置: