我需要以编程方式找到有关TFS中分支的信息.例如,我感兴趣的主要内容是给根文件夹$/MyProject/Project1我需要找出其他文件夹已从中分支出来.我只是在正确的API方法之后.
假设我已连接到TFS服务器并具有访问权限VersionControlServer和Workspace类实例.
Rob*_*cus 22
好吧,这比我想象的要容易和困难.我能够从几个不同的来源把它拉到一起,但这似乎有效.我会警告你,这里没有错误处理,如果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);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13165 次 |
| 最近记录: |