检索TFS集合和项目列表

时间:2019-04-17 15:37:41

标签: git visual-studio github tfs tfs2010

我正在尝试从TFS服务器获取每个集合下的项目列表,但是我找不到任何简便的方法。找到了一个poweshell脚本,但是需要安装V3,而我只有PS V2,并且花很长时间进行版本升级。还有其他方法可以从TFS获取馆藏和项目清单吗? TIA!

1 个答案:

答案 0 :(得分:0)

您可以使用此C#示例获取列表:

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            TfsConfigurationServer tfsc = new TfsConfigurationServer(new Uri("http://{server_name}:8080/tfs"));
            tfsc.EnsureAuthenticated();

            var collectionNodes = tfsc.CatalogNode.QueryChildren(
                new[] { CatalogResourceTypes.ProjectCollection },
                false, CatalogQueryOptions.None);

            foreach(CatalogNode collection in collectionNodes)
            {
                Console.WriteLine("Collection {0} contains projects:", collection.Resource.DisplayName);
                var tpc = tfsc.GetTeamProjectCollection(new Guid(collection.Resource.Properties["InstanceId"]));

                var projectNodes = tpc.CatalogNode.QueryChildren(
                new[] { CatalogResourceTypes.TeamProject },
                false, CatalogQueryOptions.None);

                foreach (CatalogNode project in projectNodes)
                    Console.WriteLine(project.Resource.DisplayName);
            }
        }
    }
}

对“ C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ CommonExtensions \ Microsoft \ TeamFoundation \ Team Explorer”中的库的引用:

  1. Microsoft.TeamFoundation.Client.dll
  2. Microsoft.TeamFoundation.Common.dll

或者您可以尝试Microsoft.TeamFoundationServer.ExtendedClient