Luk*_*kas 12 msbuild tfs workitem
我需要一个在构建之间制作的变更集(或工作项)列表(如果必要,我可以标记构建).我需要为我们的测试团队提供该列表(以及发布'changelist')
MSBuild任务是否能够检索该列表并保存为文件(然后我可以进一步处理该列表.
或者我可能需要从C#代码连接到TFS并自己检索该列表(我熟悉在C#中检索WorkItems)
小智 11
我知道这个帖子已经有几年了,但我在尝试完成同样的事情时发现了它.我一直在研究这个问题几天,并提出了一个完成这项特定任务的解决方案.(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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
希望这有助于下一个尝试完成任务的人!
我们在 TFS 构建过程中做了类似的事情。为此,我们在 C# 中创建了一个 MSBuild 自定义任务,用于调用 TFS 来获取项目。创建自定义任务非常简单。
这是一篇帮助您开始编写 MSBuild 任务的文章。 http://msdn.microsoft.com/en-us/library/t9883dzc.aspx
我假设您已经知道如何根据您的问题调用 TFS。
| 归档时间: |
|
| 查看次数: |
25596 次 |
| 最近记录: |