2014-02-24 113 views
1

我需要從現有的TFS 2012安裝中收集信息,管理員在團隊項目描述中放入一些有用的數據。檢索TFS項目描述

我認爲這將很容易檢索它,但我看不到這些數據公開的任何Microsoft.TeamFoundation.WorkItemTracking.Client.Project屬性或Microsoft.TeamFoundation.Server.ProjectInfo屬性。 我想過查詢Collection數據庫,但表tbl_projects和tbl_project_properties沒有描述數據。

回答

2

我相信Microsoft.TeamFoundation.Framework.Client.CatalogResource類具有您正在查找的Description屬性。下面的代碼連接到TFS配置服務器,然後寫出項目集合和團隊項目名稱和說明。

private static void WriteOutTeamProjects() 
    { 
     // 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 = new Uri("http://vsalm:8080/tfs/"); 

     TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri); 

     // 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) 
     { 
      // Use the InstanceId property to get the team project collection 
      Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]); 
      TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId); 

      // 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.WriteLine(" Description: " + projectNode.Resource.Description); 
      } 
     } 

     Console.WriteLine("Press any key to finish..."); 
     Console.ReadKey(); 
    } 
+0

不錯,同時我發現一個SQL查詢到相同的數據併發布這個其他答案也。 –

+0

要使用'CatalogResourceTypes'和'CatalogQueryOptions',您需要引用'Microsoft.TeamFoundation.Server.Core'。但是,這個程序集在我的系統中不可用。你有一個想法,我能做什麼? – Bobby

0

對配置數據庫的此查詢提供了相同的數據。

SELECT [DisplayName] AS ProjectName, [Description] AS ProjectDescription 
FROM [Tfs_Configuration].[dbo].[tbl_CatalogResource] 
WHERE ResourceType = (
    SELECT [Identifier] 
    FROM [Tfs_Configuration].[dbo].[tbl_CatalogResourceType] WHERE [DisplayName] = 'Team Project') 
ORDER BY 1