【问题标题】:Team Foundation Server SDK samplesTeam Foundation Server SDK 示例
【发布时间】:2017-06-25 00:45:34
【问题描述】:

谁能给我指点 TFS SDK 的 C# 示例?

我找了好久,似乎找不到示例或 SDK。

【问题讨论】:

    标签: tfs sdk


    【解决方案1】:

    您可以查看this official documentation,其中包含一些示例和所有命名空间。

    以下示例显示了如何以编程方式连接到运行 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);
                    }
                }
            }
        }
    }
    

    一些精彩的博客,包括多个 API 示例供您参考:

    【讨论】:

      猜你喜欢
      • 2010-09-15
      • 1970-01-01
      • 1970-01-01
      • 2010-09-26
      • 2010-10-11
      • 2018-08-30
      • 2014-05-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多