如何找出构建 TFS 2015 版本的变更集? [英] How to figure out the changeset a TFS 2015 build was build from?

查看:28
本文介绍了如何找出构建 TFS 2015 版本的变更集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只分发由我的 TFS 构建定义之一构建的二进制文件,每个构建都收到一个唯一的版本号 (1.0.$yy$dayofyear.$rev).构建名称的名称包含此版本号.版本号由 PowerShell 脚本设置为二进制文件的程序集版本和文件版本.我只有 60 天的构建结果保留期(包括我的 drop 文件夹中的构建二进制文件),现在我想知道:我怎么可能找出某个一年前的版本号,它是从哪个变更集构建的,以便我可以看看源代码或完全重建二进制文件吗?我是否必须在构建期间以某种方式明确添加变更集信息?我是否必须在构建期间设置的版本号中对变更集编号进行编码?这两个想法似乎都不是很巧妙.

I am distributing only binaries which were built by one of my TFS build definitions and each build receives a unique version number (1.0.$yy$dayofyear.$rev). The name of the build name contains this version number. The version number is set by a PowerShell script as the assembly version and the file version of the binary. I have only a build result rentention (including the built binaries in my drop folder) of 60 days and now I am wondering: How would I possibly figure out for some version number which is one year old which changeset it was built from so that I can have a look at the source code or rebuild exactly the binary? Do I have to add the changeset info somehow during my build explicitly? Do I have to encode the changeset number in my version number which is set during the build? Both ideas don't seem very ingenious.

推荐答案

我终于想出了一个 PowerShell 脚本,我将它挂接到我的构建定义中,作为一个额外的构建步骤,就在一个类似于提议的步骤之后 这里 在所有中设置版本属性AssemblyInfo.cs 文件:

I finally came up with a PowerShell script that I hook into my build definition as an additional build step just after a step that is similar to the one proposed here which sets the version attribute in all AssemblyInfo.cs files:

$systDefinitionId = $env:SYSTEM_DEFINITIONID
$buildDefVersion = $env:BUILD_DEFINITIONVERSION
$buildDefName = $env:BUILD_DEFINITIONNAME
$buildSourceVersion = $env:BUILD_SOURCEVERSION
$buildSourceBranch = $env:BUILD_SOURCEBRANCH

$SrcPath = $env:BUILD_SOURCESDIRECTORY
$AllVersionFiles = Get-ChildItem $SrcPath AssemblyInfo.cs -recurse
$AllVersionFilesCount = ($AllVersionFiles | Measure-Object).Count

Write-Verbose "Updating $AllVersionFilesCount AssemblyInfo.cs files in path ""$SrcPath"" with source information."  -Verbose

Write-Verbose "ID of build definition:      $systDefinitionId" -Verbose
Write-Verbose "Version of build definition: $buildDefVersion" -Verbose
Write-Verbose "Name of build definition:    $buildDefName" -Verbose
Write-Verbose "Changeset to build:          $buildSourceVersion" -Verbose
Write-Verbose "Branch to build from:        $buildSourceBranch" -Verbose

foreach ($file in $AllVersionFiles)
{
(Get-Content $file.FullName) |
    %{$_ -replace 'AssemblyProduct\(""\)', "AssemblyProduct(""$buildDefName / $buildSourceVersion"")" } |
    %{$_ -replace 'AssemblySourceBranch\(""\)', "AssemblySourceBranch(@""$buildSourceBranch"")" } |
    %{$_ -replace 'AssemblySourceChangeset\(0\)', "AssemblySourceChangeset($buildSourceVersion)" } |
    %{$_ -replace 'AssemblyBuild\(""\)', "AssemblyBuild(@""$buildDefName / ID: $systDefinitionId / Version: $buildDefVersion"")" } |
Set-Content $file.FullName -Force
}

我正在修改 AssemblyProduct 属性,将构建定义名称和用于创建二进制文件的变更集写入其中.稍后,此信息会在 Windows 资源管理器中的详细信息选项卡上的 exe 或 dll 属性中可见.

I am modifying the AssemblyProduct attribute by writing into it the build definition name and the changeset which was used to create the binaries. Later on this info is visible on the properties of the exe or dll in Windows Explorer on the details tab.

此外,我定义了自定义属性AssemblySourceBranchAssemblySourceChangesetAssemblyBuild 以携带更详细的信息.它们都具有相同的结构,因此为简洁起见,仅列出 AssemblySourceChangeset 的源代码:

Moreover I have defined the custom attributes AssemblySourceBranch, AssemblySourceChangeset and AssemblyBuild to carry more detailed info. They all have the same structure, so for brevity only the source code of AssemblySourceChangeset:

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public class AssemblySourceChangesetAttribute : Attribute
{
  public AssemblySourceChangesetAttribute(uint changeset)
  {
    Changeset = changeset;
  }

  public uint Changeset { get; }
}

如果公开"可见产品字段中的信息不足以重建二进制文件,仍然会导致反射 exe 或 dll 并读取那些包含源分支信息的自定义属性,id 和存储的构建定义版本.

Should the info in the "publicly" visible product field not be enough to be able to rebuild the binary, one can still result to reflecting upon the exe or dll and read those custom attributes which have info on the source branch, the id and the version of the build definiton stored.

这篇关于如何找出构建 TFS 2015 版本的变更集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆