gpt4 book ai didi

.net - 如何以编程方式获取有关TFS中分支的信息?

转载 作者:行者123 更新时间:2023-12-03 13:29:47 25 4
gpt4 key购买 nike

我需要以编程方式查找有关TFS中分支的信息。例如,我感兴趣的主要内容是给根文件夹$ / MyProject / Project1,我希望找出从该文件夹中又分支了哪些其他文件夹。我只是在寻找正确的API方法。

假设我已经连接到TFS服务器,并且可以访问VersionControlServerWorkspace类实例。

最佳答案

好的,这比我想象的要容易和困难。我能够从几个不同的来源将其组合在一起,但这似乎可行。我会警告您,这里没有错误处理,并且如果itemSpec不存在,它会轰炸,并带有异常。

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

static void Main(string[] args)
{
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(
new Uri("http://tfs:8080"));
string srcFolder = "$/ProjectName";
var versionControl = tfs.GetService<VersionControlServer>();
ItemSpec[] specs = new ItemSpec[]{new ItemSpec(srcFolder, RecursionType.None)};

System.Console.WriteLine(string.Format("Source folder {0} was branched to:",
srcFolder));
BranchHistoryTreeItem[][] branchHistory =
versionControl.GetBranchHistory(specs, VersionSpec.Latest);

foreach (BranchHistoryTreeItem item in branchHistory[0][0].Children)
{
ShowChildren(item);
}

System.Console.WriteLine();
System.Console.WriteLine("Hit Enter to continue");
System.Console.ReadLine();
}

static void ShowChildren(BranchHistoryTreeItem parent)
{
foreach (BranchHistoryTreeItem item in parent.Children)
{
System.Console.WriteLine(
string.Format("Branched to {0}",
item.Relative.BranchToItem.ServerItem));
if (item.Children.Count > 0)
{
foreach(BranchHistoryTreeItem child in item.Children)
{
ShowChildren(child);
}
}
}
}

关于.net - 如何以编程方式获取有关TFS中分支的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4690217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com