Team Foundation Server 2010 provides us with Team Foundation Server API to manage lots of items via code. In this example we shall see how we can retrieve Build definitions for a given Team Project in a given Team Project Collection.
First you will have to add references to the following assemblies. Go to Project>Add Reference>Search for Microsoft.TeamFoundation and you will all the three assemblies required for our project.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.TeamFoundation.Common; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Build; using Microsoft.TeamFoundation.Build.Client; namespace TfbdConsole { class Program { static void Main( string [] args) { TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection( new Uri( "http://tfsserver:8080/tfs/yourProjectCollectionName/" ) , new UICredentialsProvider()); IBuildServer buildserver = tpc.GetService<ibuildserver>(); IBuildServiceHost[] buildServiceHosts = buildserver.QueryBuildServiceHosts( "*" ); IBuildDefinition[] buildDefinitions = buildserver.QueryBuildDefinitions( "NameOfYourTeamProject" ); foreach (IBuildDefinition buildDefinition in buildDefinitions) { Console.WriteLine(buildDefinition.Name); Console.WriteLine(buildDefinition.ProcessParameters.ToString()); } Console.ReadKey(); } } } |