TFS API: Two, TFS code query work items
First, we need to recognize the two classes of TFS's fetching service objects.
They were tfsconfigurationserver and tfsteamprojectcollection, and their differences were that they could get different TFS API service classes. Their difference is as follows:
Service |
Tfsconfigurationserver ( server level ) |
Tfsteamprojectcollection ( collection level ) |
Iteamfoundationregistry |
√ |
√ |
Iidentitymanagementservice |
√ |
√ |
Iteamfoundationjobservice |
√ |
√ |
Ipropertyservice |
√ |
√ |
Ieventservice |
√ |
√ |
Isecurityservice |
√ |
√ |
Ilocationservice |
√ |
√ |
Tswaclienthyperlinkservice |
√ |
√ |
Iteamprojectcollectionservice |
√ |
√ |
Iadministrationservice |
√ |
√ |
Icatalogservice |
√ |
|
Versioncontrolserver |
|
√ |
WorkItemStore |
|
√ |
Ibuildserver |
|
√ |
Itestmanagementservice |
|
√ |
Ilinking |
|
√ |
ICommonStructureService3 |
|
√ |
Iserverstatusservice |
|
√ |
Iprocesstemplates |
|
√ |
Basically we can operate all functional points on TFS through the above two classes. Let's take a look at how to use tfsteamprojectcollection to get all the items under a particular team collection and print out the project name.
First we need to import the namespace
Using Microsoft.TeamFoundation.Client;
Using Microsoft.TeamFoundation.Framework.Client;
Using Microsoft.TeamFoundation.Framework.Common;
Using Microsoft.TeamFoundation.WorkItemTracking.Client;
Using Microsoft.TeamFoundation.VersionControl.Client;
Next link TFS
Uri Tfsuri = new Uri ("Http://10.0.9.142:8080/tfs/web");
Tfsteamprojectcollection Server = new Tfsteamprojectcollection (Tfsuri);
WorkItemStore workstore = server. Getservice<workitemstore> ();
I need a special explanation here.
Http://10.0.9.142:8080/tfs/web This address must be written right, sometimes this address can actually open TFS in the browser, but not the address of the link TFS, otherwise you will be prompted such errors
TF31002: Unable to connect to this Team Foundation server:http://10.0.9.142:8080/tfs/web.
Team Foundation Server Url:http://10.0.9.142:8080/tfs/web.
How to get the correct address we need, please look at the picture.
After you link to TFS, you can query a lot of data.
Remove the project name under the Team collection URI and, if the team collection is empty, take the project under the default collection
Uri Tfsuri = new Uri ("Http://10.0.9.142:8080/tfs/web");
Tfsteamprojectcollection Server = new Tfsteamprojectcollection (Tfsuri);
WorkItemStore workstore = server. Getservice<workitemstore> ();
foreach (Project project in Workstore. Projects)
{
Console.WriteLine ("TFS Collection under Project name is:" + Project.) Name);
}
Console.WriteLine ("---------------------------------------------------------------");
The following example gets all team collections for our entire TFS server and all team names under the team collection
TFS API: Two, TFS code query work items