Search code examples
c#tfstfs-sdk

Programatically access TFS account to get project names and work items


I've been trying to access a TFS account (programatically using the TFS SDK) in order to get information such as the project names, work item names and developpment times for each work item.

I wasn't able to get project or work item information, but I was able to authenticate and access TFS using the class TfsTeamProjectCollection.

However, using the class TfsConfigurationServer, I was never able to authenticate to the server. This is a pity because the majority of examples I've seen in the web use this TfsConfigurationServer class.

The code that allows me to access TFS:

// Connect to Team Foundation Server.
NetworkCredential netCred = new NetworkCredential("myEmail@email.com", "myPassword");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://tfs.gfi.pt:4430/tfs/gfi/"),tfsCred);

tpc.Authenticate(); // This one works, and when I enter tpc I can see I am correctly signed-in in TFS (I can for instance check my full name)

ITeamProjectCollectionService projCollect = tpc.GetService<ITeamProjectCollectionService>(); //returns null :(

I have 2 questions:

  1. What is the difference between the TfsConfigurationServer and the TfsTeamProjectCollection? I know the first leads me to the Server-Level and the second to the Collection-level, but, what is the server-level and collection-level?
  2. Why am I unable to get the projectCollection when I am perfectly capable of signing-in (why does the last line returns null when I am sure I have 2 projects on TFS)?

Solution

  • Regarding question #1, you can find some whys in Introducing the TfsConnection, TfsConfigurationServer and TfsTeamProjectCollection Classes. Shortly, you can have many user databases, i.e. Collection, managed by a single TFS instance, i.e. the Server.