2013-03-21 74 views
0

在這裏workItemStore總是返回空.....我想要日誌問題tp TFS作爲nugs。但不能becoz空exception..help的,這樣做是grealy讚賞...謝謝....TFS WorkItems始終返回空值

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); 
     } 
    } 

回答

3

嘗試這種方式來創建WorkItemStore

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

嗨,我試着上面的代碼它說..「無法加載程序集Microsoft.Teamfoundation.client.dll」..我使用的DLL版本11 ... – user2155788 2013-03-26 04:55:00

+0

是啊!這是獲取WorkItemStore的方法!讓我從頭痛中解脫出來。非常感謝! +1 – misha 2014-01-08 13:27:12

+0

謝謝。這種方式而不是返回null,我們得到一個Exception來知道要修復什麼。非常感謝你 – 2015-08-08 04:41:50

1

不要將dll複製並粘貼到bin中,您必須直接從路徑添加參考:

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 

它對我很好用。