TFS API Insights

By Anoop Madhusudanan

Vote on HN
As I was recently working with TFS Client APIs, here are few thoughts on the same.

Logging Into TFS Server

To log in to the TFS Server using the TFS Client APIs, you can either use the domain authentication, or provide the username or password explicitly

- Logging in using the current windows user

TeamFoundationServer _tfsServer = new TeamFoundationServer("serverUrl");

- Logging in using a specific network credential

 _tfsServer = new TeamFoundationServer(
                       new System.Net.NetworkCredential
                               ("userName", "password", "domain"));

Getting all the projects - Using VersionControlServer

After logging in, you can get all the projects and project items in TFS as shown below. We are reading the latest version for each item

VersionControlServer _versonControlServer=_tfsServer.GetService
                (typeof(VersionControlServer)) as VersionControlServer;

 foreach (var teamProject in 
       //Get all the items in the project
       ItemSet items = 
               (teamProject.ServerItem, VersionSpec.Latest, 
       foreach (Item item in items.Items)
                        { //do your stuff with each project item }


Reading all users - Using GroupSecurityService Now, you can read all users using the IGroupSecurityService, as shown.

   IGroupSecurityService _groupSecurityService = 
             as IGroupSecurityService;

Identity identity = _groupSecurityService.ReadIdentity
  (SearchFactor.EveryoneApplicationGroup, null, QueryMembership.Expanded);

foreach (Identity user in _groupSecurityService.ReadIdentities
          (SearchFactor.Sid, identity.Members, QueryMembership.None))
                   //do something with the users
TFS API is very simple and intuitive, and in next post I'll explain some work item related methods.

No comments:

Post a Comment

Please keep your comments clean.

© 2012. All Rights Reserved.