I'm trying to programmatically get a list of all the branches in TFS for Visual Studio 2013. After doing some research I found this blog that details how to get the branches:
Displaying all branch hierarchies in TFS 2010
I modified the code to instead store everything in a list.
private void Setup()
{
string serverName = "serverName"; //in the code this is set to the actual server name
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(serverName));
VersionControlServer vcs = tfs.GetService<VersionControlServer>();
var bos = vcs.QueryRootBranchObjects(RecursionType.OneLevel);
Array.ForEach(bos, (bo) => DisplayAllBranches(bo, vcs));
}
private void DisplayAllBranches(BranchObject bo, VersionControlServer vcs)
{
_listOfBranches.Add(bo.Properties.RootItem.Item);
var childBos = vcs.QueryBranchObjects(bo.Properties.RootItem, RecursionType.OneLevel);
foreach (var child in childBos)
{
if (child.Properties.RootItem.Item == bo.Properties.RootItem.Item)
continue;
DisplayAllBranches(child, vcs);
}
}
The problem I'm having is that the BranchObjects[] bos is always empty. Is there something I'm missing or is there a better way to get a list of all the branches?