Few days ago, I was needing to be able to retrieve some informations about the builds we had launched. I was so needing to work with the TFS API.
To do this, you must have Visual Studio and a Team Explorer installed.
-
Create a new application (a console application for example)
-
Add a reference to the DLLs
-
Microsoft.TeamFoundation.Build.Client
-
Microsoft.TeamFoundation.Build.Common
-
Microsoft.TeamFoundation.Client
-
Microsoft.TeamFoundation.Common
You can find these DLLs in the folder "Program Files\Microsoft Visual Studio X.X\Common7\IDE\Private Assemblies
And after you can very simply interrogate the TFS API as for example :
string tfsUrl = "http://YourTFS:8080";
string teamProject = "Your Team Project Name";
string teamBuildType = "The name of your team build";
TeamFoundationServer server = TeamFoundationServerFactory.GetServer(tfsUrl);
BuildStore buildStore = server.GetService(typeof(BuildStore)) as BuildStore;
BuildData[] buildDatas = buildStore.GetListOfBuilds(teamProject, teamBuildType);
foreach ( BuildData buildData in buildDatas )
{
PlatformFlavorData[] platforms = buildStore.GetPlatformFlavorsForBuild(buildData.BuildUri);
foreach ( var platformFlavor in platforms )
{
TestResultData[] testResults = buildStore.GetTestResultsForBuild(buildData.BuildUri, platformFlavor.PlatformName, platformFlavor.FlavorName);
foreach ( TestResultData testResultData in testResults )
{
}
}
}
Quite easy no ?
Juste one things to know : this code will work, whatever the version of your Visual Studio and TFS. But all the class you use here are deprecated under TFS 2008 (but will still work).
So how to do the same thing using the new TFS 2008's classes ? To be seen in a future post ! ;-)