当前位置 : 主页 > 网络推广 > seo >

tfs – 如何检索在构建之间签入的更改集(或工作项)列表?

来源:互联网 收集:自由互联 发布时间:2021-06-16
我需要一个在构建之间进行的变更集(或工作项)列表(如果需要,我可以标记构建). 我需要我们的测试团队的名单(并发布’changelist’) MSBuild任务能够检索该列表并保存为文件(然后我可以进
我需要一个在构建之间进行的变更集(或工作项)列表(如果需要,我可以标记构建).
我需要我们的测试团队的名单(并发布’changelist’)

MSBuild任务能够检索该列表并保存为文件(然后我可以进一步处理该列表.
或者也许我需要从C#代码连接到TFS,并自己检索该列表(我熟悉在C#中检索WorkItems)

我知道这个线程是几岁,但是当尝试完成同样的事情时,我发现它.
我一直在为此工作几天,并提出了一个解决方案来完成这项具体任务. (TFS 2010)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Build.Client;


namespace BranchMergeHistoryTest
{
  class Program
  {
    private static Uri tfsUri = new Uri("http://sctf:8080/tfs");
    private static TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);

    static void Main(string[] args)
    {

      IBuildServer buildServer = tfs.GetService<IBuildServer>();
      IBuildDefinition buildDef = buildServer.GetBuildDefinition("Project", "Specific Build");
      IOrderedEnumerable<IBuildDetail> builds = buildServer.QueryBuilds(buildDef).OrderByDescending(build => build.LastChangedOn);
      /* I had to use some logic to find the last two builds that had actual changesets attached - we have some builds that don't have attached changesets. You may want to do the same. */ 
      IBuildDetail newestBuild = builds.ElementAt(0); 
      IBuildDetail priorBuild = builds.ElementAt(1);

      string newestBuildChangesetId = newestBuild.Information.GetNodesByType("AssociatedChangeset")[0].Fields["ChangesetId"];
      string priorBuildChangesetId = priorBuild.Information.GetNodesByType("AssociatedChangeset")[0].Fields["ChangesetId"];

      VersionControlServer vcs = tfs.GetService<VersionControlServer>();
      const string sourceBranch = @"$SourceBranch-ProbablyHEAD";
      const string targetBranch = @"$TargetBranch-ProbablyRelease";
      VersionSpec versionFrom = VersionSpec.ParseSingleSpec(newestBuildChangesetId, null);
      VersionSpec versionTo = VersionSpec.ParseSingleSpec(priorBuildChangesetId, null);
      ChangesetMergeDetails results = vcs.QueryMergesWithDetails(sourceBranch, VersionSpec.Latest, 0, targetBranch,VersionSpec.Latest, 0, versionFrom, versionTo, RecursionType.Full);
      foreach(Changeset change in results.Changesets)
      {
        Changeset details = vcs.GetChangeset(change.ChangesetId);
        // extract info about the changeset
      }
    }
  }
}

希望这有助于下一个人试图完成任务!

网友评论