以编程方式获取 TFS 责备(注释)数据 [英] Programmatically get TFS blame (annotation) data
问题描述
我正在尝试为 Team Foundation Server 2010 实现一个插件,该插件将创建关于团队项目中用户的报告.从概念上讲,为了正确实现这个插件,我所需要的只是访问您在 Visual Studio 中使用注释"功能时获得的相同数据:我需要知道谁是最后一个作者给定的代码行.
I'm trying to implement a plugin for Team Foundation Server 2010 that will create reports about users in a team project. Conceptually, all I need in order to properly implement this plugin is access to the same data that you get when you use the "Annotate" feature in Visual Studio: I need to be able to tell who was the last person to author a given line of code.
我已经在 Internet 上搜索文档或代码示例,但我能找到的只是诸如 使用 TFS 命令行工具 或看似不完整的 代码示例.
I've scoured the Internet for documentation or code samples, but all that I can find are either suggestions such as using the TFS command-line tools or seemingly incomplete code samples.
我不介意在客户端代码中做很多繁重的工作,但似乎没有一种明显的方法来获取有关代码中内容的有用作者数据变更集,也不是来自合并详细信息返回.
I don't mind doing a lot of heavy lifting in the client code, but there doesn't seem to be an obvious way to get useful authorship data about the contents of the code in a Changeset, nor from the merge details return.
推荐答案
与此同时,我找到了一个执行 Team Foundation Power Tools 处理并解析其输出:
Meanwhile I found a working solution that executes Team Foundation Power Tools process and parses its output:
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();
}
}
这篇关于以编程方式获取 TFS 责备(注释)数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!