TFS API Part 33– Get Build Definitions and Build Details


TFS API Part 33– Get Build Definitions and Build Details

Doing some major projects in WF under Team Build 2010 I decide it’s the right time to start writing about Build API in TFS 2010.

This part is very very basic and in later posts I’ll show some cool stuff in Build 2010 API.


Download Demo Project

Step 1: Create Project and Add Reference

Create an WPF/WinForm application and add the following references:

First add reference for

  • Microsoft.TeamFoundation.dll
  • Microsoft.TeamFoundation.Build.Client
  • Microsoft.TeamFoundation.Build.Common.dll
  • Microsoft.TeamFoundation.dll

All files located under – c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\

Step 2: Connect to Team Foundation Server

(TFS API Part 20: Bye TeamFoundationServer and Welcome TfsTeamProjectCollection)

private TfsTeamProjectCollection server;
private IBuildServer buildServer;
private void btn_connect_Click(object sender, RoutedEventArgs e)
    TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);

    if (tpp.SelectedTeamProjectCollection != null)
        server = tpp.SelectedTeamProjectCollection;
        buildServer = (IBuildServer)server.GetService(typeof(IBuildServer));

        //QueryBuildDefinitions(String) Gets the build definitions for the specified team project.
        //QueryBuildDefinitions(IBuildDefinitionSpec) Gets a single build definition query result for a specified build definition specification.
        //QueryBuildDefinitions(IBuildDefinitionSpec[]) Gets the build definition query results for a specified array of build definition specifications.
        //QueryBuildDefinitions(String, QueryOptions) Gets the build definitions for the specified team project. The specified query options determine the amount of data that is retrieved in the query.
        // IBuildDefinition Interface ->
        BuildDefinitions.ItemsSource = buildServer.QueryBuildDefinitions(tpp.SelectedProjects[0].Name);

Step 3: Get Builds From Build Definition

private void BuildDefinitions_SelectionChanged(object sender, SelectionChangedEventArgs e)
    if (BuildDefinitions.SelectedItem != null)
        IBuildDefinition def = BuildDefinitions.SelectedItem as IBuildDefinition;
        //IBuildDetail Interface ->
        Builds.ItemsSource = def.QueryBuilds();

Download Demo Project

Add comment
facebook linkedin twitter email

Leave a Reply


  1. MarcoW28/03/2011 ב 09:56

    Thanks for te code sample. Was a great help.

  2. Aaron10/08/2011 ב 05:47

    Agreed, excellent demo and really useful.

  3. vijay22/10/2011 ב 15:49

    It is very helpful. Thanks. You ROCK