tfsteam-project

Retrieving a TFS project description


I need to collect information from an existing TFS 2012 installation and the administrator put some useful data in the Team Project description.

I thought it would be easy to retrieve it, but I cannot see this data exposed by any property of Microsoft.TeamFoundation.WorkItemTracking.Client.Project nor Microsoft.TeamFoundation.Server.ProjectInfo. I thought of querying the Collection databases, but the tables tbl_projects and tbl_project_properties do not have the description data.


Solution

  • I believe the Microsoft.TeamFoundation.Framework.Client.CatalogResource class has the Description property you are looking for. The code below connects to the TFS configuration server and then writes out the project collections and team project names and descriptions.

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