Saturday, January 4, 2014

TFS API: Get Project Collection Team Members

I have been working extensively with TFS (Team Foundation Service) API, and enjoying the miscellaneous challenges therein. One such challenge was to display a list of valid team members to assign work items to. And following the TFS online experience, the Assign To field must display all the user oat the collection level.

I saw a couple of approaches using the IGroupSecurityService interface that is a part of the Microsoft.TeamFoundation.Server but it has been marked as obsolete and instead a hint is provided to use the better alternative which is IIdentityManagementService. So here is a simple code snippet on how to get a list of team members ordered alphabetically.

Please note that the collection variable is simply an instance of  the team project collection class

new TfsTeamProjectCollection(collectionUrl, credentials)

Also note that when developing using the TFS API, you will need the following assemblies and namespaces referenced:
using Microsoft.TeamFoundation;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;

among others..

Here is the snippet::