TFS2010 API: Retrieving a list of Process Templates on the server.
I thought I’d post some utility code that I’ve been playing with to retrieve information about the Process Templates available on a TFS 2010 instance.
As you can see from the code, each TeamProjectCollection has its own store of Process Templates (in TFS 2008 there was in effect a single “Project Collection”) so we need to look through each collection to retrieve the templates that have been uploaded to it.
You’ll need references to Microsoft.TeamFoundation.dll, Microsoft.TeamFoundation.Client.dll, Microsoft.TeamFoundation.Common.dll. On a machine with Visual Studio 2010 installed they should be found in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0 or C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0 depending on whether you have a 64-bit version of Windows or not. You’ll also need to set the Target Framework to .NET Framework 3.5 as the assemblies required are in the v2 GAC.
This code will work against TFS2010 Beta 2 but is not guaranteed to work in the RTM.
using System; using System.Collections.Generic; using System.Text; using Microsoft.TeamFoundation.Framework.Client; using Microsoft.TeamFoundation.Framework.Common; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Server; namespace TFSUtils { class Program { static void Main(string[] args) { //replace this with the URL to your TFS instance. Uri tfsUri = new Uri("http://sptfs02:8080/tfs"); TeamFoundationApplicationInstance tfai = new TeamFoundationApplicationInstance(tfsUri, new UICredentialsProvider()); tfai.EnsureAuthenticated(); ITeamProjectCollectionService collectionService = tfai.GetService<ITeamProjectCollectionService>(); IList<TeamProjectCollection> collections = collectionService.GetCollections(); foreach (TeamProjectCollection collection in collections) { if (collection.State == TeamFoundationServiceHostStatus.Started) { Console.WriteLine(String.Format("\nCollection: {0}", collection.Name)); IProcessTemplates processTemplates = tfai.GetTeamFoundationServer(collection.Id).GetService<IProcessTemplates>(); TemplateHeader[] templateHeaders = processTemplates.TemplateHeaders(); foreach (TemplateHeader header in templateHeaders) { Console.WriteLine(String.Format("\t{0} {1}", header.TemplateId, header.Name)); } } } Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); } } }

