使用c#console application

时间:2016-08-12 09:20:40

标签: c# tfs

我正在开发一个c#控制台应用程序,我想连接到我的TFS服务器并从中访问信息。

我的TFS服务器是:http://vstfpg05:8080/tfs/ESITAPP

基本上,我们通过TFS维护票务系统,我想访问票证的服务名称。

enter image description here

上面是我的tfs系统的剪辑。

1 个答案:

答案 0 :(得分:2)

如果您使用客户端API 并使用以下示例,则可以以编程方式连接到运行Team Foundation的服务器,然后访问该服务器上的团队项目:

using System;
using System.Collections.ObjectModel;
using Microsoft.TeamFoundation.Client; 
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Framework.Client;

namespace TfsApplication
{
    class Program
    {
        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("http://Server:Port/VDir") : new Uri(args[0]);

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

更多详细信息请参阅MSDN上的本教程:Connect to Team Foundation Server from a Console Application