Search This Blog

Tuesday, November 07, 2006

How to Get Build Types List

There's no method in TFS API that retrieves a list of build types for a project. I looked inside the BuildStore interface and found nothing. Later I saw somewhere that it is not exposed so I wrote my own implementation using source control API. I'm retrieving a list of folders under the TeamBuildTypes folder.

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

public string[] GetBuildTypes(string serverName, string teamProject)
{
TeamFoundationServer tfs = new TeamFoundationServer(serverName, CredentialCache.DefaultCredentials);
tfs.EnsureAuthenticated();
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
ItemSet itemSet = vcs.GetItems("$/" + teamProject + "/TeamBuildTypes", VersionSpec.Latest, RecursionType.OneLevel, DeletedState.NonDeleted, ItemType.Folder);
List<string> buildTypes = new List<string>();
foreach (Item item in itemSet.Items)
{
string buildType = Path.GetFileName(item.ServerItem);
if (buildType != "TeamBuildTypes")
{
buildTypes.Add(buildType);
}
}
return buildTypes.ToArray();
}

2 comments:

Eduardo Bottcher said...

Thank you so Much, that helped me A LOT!

Circuswinkel Malabarte said...

Veryy creative post