-->

TFS WorkItems returns null always

2019-08-17 13:05发布

问题:

Here workItemStore always returns null.....i want log issues tp TFS as a nugs. But not able to do so becoz of null exception..help is grealy appreciated...Thank you....

var networkCredential = new NetworkCredential(userName, password, domainName);

var credential = (ICredentials)networkCredential;

//Connect to TFS Project Collection, provide server URL in format http:// ServerName:Port/Collection


var tfs = new TfsTeamProjectCollection(
TfsTeamProjectCollection.GetFullyQualifiedUriForName(TfsConnectionUri), credential);

//Check whether valid TFS user or not

tfs.EnsureAuthenticated();

var workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

//Iterate Through Projects
    foreach (Project tfs_project in workItemStore .Projects)
    {
       Console.WriteLine(tfs_project.Name);

       //Perform WIQL Query 
       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);
       }
     }

回答1:

Try it this way to create the WorkItemStore

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(TfsServerURI), nc); 
var _wis = new WorkItemStore(tfs);


回答2:

Don't copy and paste the dll to bin, you have to add the reference directly from the path:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Client.dll

It work prefectlly to me.