2013-03-21 46 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 

它对我很好用。