TFS 存储库模块内的标签总数

Total number of labels inside a module of TFS repository

我需要找出 Team Foundation 存储库中集合的每个模块内有多少标签。 我正在使用 TFS 2013。 我知道我们可以从 Visual Studio 得到它。但是我们需要一个脚本来获取标签的数量作为输出。 任何人都可以帮助我获得 C# 或 Powershell 代码以获得相同的代码吗?

TIA

您可以使用 .NET 客户端库来获取:.NET client libraries for Visual Studio Team Services (and TFS)

代码示例:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace GetLabels
{
    class Program
    {
        static void Main(string[] args)
        {
            string tfscollection = "http://xxx:8080/tfs/defaultcollection";
            TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(tfscollection));
            VersionControlServer vcs = ttpc.GetService<VersionControlServer>();
            string labelname = null;
            string labelscope = "$/";
            string owner = null;
            bool includeitem = false;
            int labelnumber;
            VersionControlLabel[] labels = vcs.QueryLabels(labelname,labelscope,owner,includeitem);
            labelnumber = labels.Length;
            Console.WriteLine(labelnumber);
            Console.ReadLine();
        }
    }
}