【问题标题】:Programmatically get TFS blame (annotation) data以编程方式获取 TFS 责备(注释)数据
【发布时间】:2015-10-11 10:27:59
【问题描述】:

我正在尝试为 Team Foundation Server 2010 实现一个插件,该插件将创建有关团队项目中用户的报告。从概念上讲,为了正确实现这个插件,我只需要访问在 Visual Studio 中使用“注释”功能时获得的相同数据:我需要能够分辨出谁是最后一个创作者给定的代码行。

我在 Internet 上搜索了文档或代码示例,但我只能找到诸如 using the TFS command-line tools 之类的建议或看似不完整的 code samples

我不介意在客户端代码中做大量繁重的工作,但似乎没有一种明显的方法可以在Changeset,也不是从merge details返回。

【问题讨论】:

    标签: c# tfs annotate blame


    【解决方案1】:

    同时,我找到了一个可以执行Team Foundation Power Tools 进程并解析其输出的可行解决方案:

    private readonly Regex m_Regex = new Regex(@"^(?<changeset>\d+)(?<codeLine>.*)", RegexOptions.Compiled | RegexOptions.Multiline);
    
    public List<Changeset> GetAnnotations(string filepath, string codeText)
        {
            var versionControlServer = CreateVersionControlServer();
    
            return m_Regex.Matches(ExecutePowerTools(filepath))
                .Cast<Match>()
                .Where(m => m.Groups["codeLine"].Value.Contains(codeText))
                .Select(v => versionControlServer.GetChangeset(int.Parse(v.Groups["changeset"].Value), false, false))
                .ToList();
        }
    
        private static VersionControlServer CreateVersionControlServer()
        {
            var projectCollection = new TfsTeamProjectCollection(new Uri(@"TFS URL"));
            var versionControlServer = projectCollection.GetService<VersionControlServer>();
            return versionControlServer;
        }
    
        private static string ExecutePowerTools(string filepath)
        {
            using (var process = Process.Start(TfptLocation, string.Format("annotate /noprompt {0}", filepath)))
            {
                process.WaitForExit();
                return process.StandardOutput.ReadToEnd();
            }
        }
    

    【讨论】:

    • 我刚刚实现了这个,它并没有告诉你每一行的所有者,只有变更集和代码......
    • @im1dermike,你是对的。这对我的用例来说已经足够了。
    【解决方案2】:

    我有非常相似的要求来获取文件中特定属性的详细信息,例如谁添加、何时添加、相关工作项等;以下 GitHub 项目正在实施以获取所需的详细信息并需要对工作进行最小的更改-

    SonarQube SCM TFVC plugin

    它需要从安装了 Team Foundation Server 对象模型的 Windows 机器上执行分析(TFS 2013 下载)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-09
      • 1970-01-01
      • 2012-06-25
      • 1970-01-01
      • 2013-07-23
      • 2015-07-05
      • 1970-01-01
      相关资源
      最近更新 更多