# Thursday, 21 May 2015

This post is more for my own reference as I spent a bit of time trying to figure this one out. For a long time now you have been able to choose your own Team field in TFS and let TFS know this using the following method https://msdn.microsoft.com/en-us/library/vstudio/dn144940.aspx . I was recently working on an application where I needed to know the Team Fields name programmatically.  Below is the code I used to do this.

For the code below to work you will need to include

  • Microsoft.TeamFoundation.Client
  • Microsoft.TeamFoundation.Framework.Client;
  • Microsoft.TeamFoundation.Framework.Common;

In the example below we pass in the Guid of the TFS Collection we are after followed by the TFS project name. We then use the Process Configuration Service to get us the details about the project

1 var _tfsTeamProjectCollection = new TfsTeamProjectCollection(new Uri(_tfsUrl), 2 new System.Net.NetworkCredential(_tfsUserName, _tfsPassword)); 3 4 _tfsTeamProjectCollection.EnsureAuthenticated(); 5 6 var teamProjectCollection = 7 _tfsTeamProjectCollection.ConfigurationServer.GetTeamProjectCollection(tfsCollectionGuid); 8 9 var settings = teamProjectCollection.GetService<ProjectProcessConfigurationService>(); 10 11 ICommonStructureService4 cssService = teamProjectCollection.GetService<ICommonStructureService4>(); 12 13 var projectInfo = cssService.GetProjectFromName(projectName); 14 15 var proc = settings.GetProcessConfiguration(projectInfo.Uri); 16 17 var sets = proc.TypeFields; 18 19 string teamField = null; 20 21 foreach (var typeField in sets) 22 { 23 if (typeField.Type == FieldTypeEnum.Team) 24 { 25 teamField = typeField.Name; 26 } 27 }

I am sure the above code example can be tidied up and adapted a bit more.

Tags: TFS

Thursday, 21 May 2015 09:19:40 (GMT Daylight Time, UTC+01:00)  #    Comments [0]

All comments require the approval of the site owner before being displayed.
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview