mars 10

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.

  1. Create a new application (a console application for example)
  2. Add a reference to the DLLs
    1. Microsoft.TeamFoundation.Build.Client
    2. Microsoft.TeamFoundation.Build.Common
    3. Microsoft.TeamFoundation.Client
    4. 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";


//Connect to the Team Foundation Server using the credentials

//of the currently logged person

TeamFoundationServer server = TeamFoundationServerFactory.GetServer(tfsUrl);

//Access the build service

BuildStore buildStore = server.GetService(typeof(BuildStore)) as BuildStore;

//and get the list of builds

BuildData[] buildDatas = buildStore.GetListOfBuilds(teamProject, teamBuildType);


//Iterate on all your builds

foreach ( BuildData buildData in buildDatas )


   PlatformFlavorData[] platforms = buildStore.GetPlatformFlavorsForBuild(buildData.BuildUri);


   // Iterate, for a specific build,

   // on all the build platform and flavor you have defined

   foreach ( var platformFlavor in platforms )


      TestResultData[] testResults = buildStore.GetTestResultsForBuild(buildData.BuildUri, platformFlavor.PlatformName, platformFlavor.FlavorName);


      foreach ( TestResultData testResultData in testResults )


         /* Here for each build platform and flavor

         * you are iterating on the test results





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 ! ;-)



Posted on jeudi, 19 mars 2009 13:52

This shows how to do it the "new" way.

Ajouter un commentaire

  • Commentaire
  • Aperçu immédiat