2014-01-27 67 views
1

美好的一天!如何通过c从tfs获取所有工作项目#

我尝试从TFS(2010)的Collection中获取所有WorkItems。 我发现blog一些代码的例子,但它不工作良好:

ICommonStructureService Iss = (ICommonStructureService)projCollection.GetService(typeof(ICommonStructureService)); 

这行代码返回一个无差错不能连接到TFS(相同的代码连接孔)。 好吧,我试图重写这段代码,并尝试这个(从MSDN另一个工作为例):

private static String _tfsURI ="http:tfsServer:port/tfsUrl" 
static void Main(string[] args) 
    { 
     // Connect to Team Foundation Server 
     //  Server is the name of the server that is running the application tier for Team Foundation. 
     //  Port is the port that Team Foundation uses. The default port is 8080. 
     //  VDir is the virtual path to the Team Foundation application. The default path is tfs. 
     Uri tfsUri = (args.Length < 1) ? 
      new Uri(_tfsURI) : new Uri(args[0]); 

     TfsConfigurationServer configurationServer = 
      TfsConfigurationServerFactory.GetConfigurationServer(tfsUri); 

     Console.WriteLine("Get the catalog of team project collections \n"); 
     // Get the catalog of team project collections 
     ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
      new[] { CatalogResourceTypes.ProjectCollection }, 
      false, CatalogQueryOptions.None); 
     // List the team project collections 
     foreach (CatalogNode collectionNode in collectionNodes) 
     { 
      Console.WriteLine(collectionNode.Resource.DisplayName); 

      // Use the InstanceId property to get the team project collection 
      Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]); 
      TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId); 


        ICommonStructureService Iis = (ICommonStructureService)teamProjectCollection.GetService(typeof(ICommonStructureService)); 
       ProjectInfo[] projInfo = Iis.ListAllProjects(); 
       // WorkItemStore wis = (WorkItemStore)teamProjectCollection.GetService(); 

       var wis = (WorkItemStore)teamProjectCollection.GetService(typeof(ICommonStructureService)); 

      foreach (var p in projInfo) 
       { 

        Console.WriteLine("Name:" + p.Name + "Status" + p.Status); 
        var wic = wis.Query(" SELECT [System.Id], [System.WorkItemType]," + 
      " [System.State], [System.AssignedTo], [System.Title] " + 
       " FROM WorkItems " + 
       " WHERE [System.TeamProject] = '" + p.Name + 
       "' ORDER BY [System.WorkItemType], [System.Id]"); 

        Console.WriteLine("wic.Count:"+wic.Count); 

        foreach (var wi in wic) 
        { 

         Console.WriteLine(wi.Id); 
         Console.WriteLine(wi.Title); 
        } 

       } 

      // Print the name of the team project collection 
       Console.WriteLine("Collection: " + teamProjectCollection.Name); 

      // Get a catalog of team projects for the collection 
      ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
       new[] { CatalogResourceTypes.TeamProject }, 
       false, CatalogQueryOptions.None); 

      // List the team projects in the collection 
      foreach (CatalogNode projectNode in projectNodes) 
      { 
       Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName); 

      } 
     } 
     Console.ReadLine(); 
    } 

所以,我得到错误:无法施展的“Microsoft.TeamFoundation.Proxy.CommonStructureService”对象类型“微软.TeamFoundation.WorkItemTracking.Client.WorkItemStore”。

请帮我热点来获取Tfs的所有工作项目。

回答

4

此行

var wis = (WorkItemStore)teamProjectCollection.GetService(typeof(ICommonStructureService)); 

显然是错误的。应该更简单

var wis = teamProjectCollection.GetService<WorkItemStore>(); 
+0

非常好的答案,谢谢。 – user1477388

相关问题