Introduction
I've worked on a project that must have the ability to integrate with Team Foundation Server. I tried to search CodeProject, but unfortunately found only one article concerning this. I was quite confused about the topic, but got it all clear - there is a very good documentation of TFS programming in MSDN. So, in my post, I'll outline links to the source information and will present a short piece of code for novice developers.
Before starting
Working with TFS
This is an example of how to connect to a TFS server, and retrieve Projects and their WorkItems using WIQL (WorkItem Query Language, see links):
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
public void WorkWithTFS(string login, string password, string tfsName)
{
NetworkCredential tfsCredential = new NetworkCredential(login, password);
TeamFoundationServer tfs = new TeamFoundationServer(tfsName, tfsCredential);
tfs.Authenticate();
WorkItemStore wis = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
foreach (Project tfs_project in wis.Projects)
{
Console.WriteLine(tfs_project.Name);
WorkItemCollection wic = wis.Query(
" SELECT [System.Id], [System.WorkItemType],"+
" [System.State], [System.AssignedTo], [System.Title] "+
" FROM WorkItems " +
" WHERE [System.TeamProject] = '" + tfs_project.Name +
"' ORDER BY [System.WorkItemType], [System.Id]");
foreach (WorkItem wi in wic)
{
Console.WriteLine(wi.Title + "["+wi.Type.Name+"]"+wi.Description);
}
}
}
You can also use Queries stored on the TFS server to retrieve WorkItems.
Also, the TFS SDK allows you to completely manage the TFS Server; for more information search MSDN.
Links
History
- 23 June 2007: First version.