我正在尝试为 Team Foundation Server 2010 实现一个插件,该插件将创建有关团队项目中的用户的报告。从概念上讲,为了正确实现此插件,我需要访问与在 Visual Studio 中使用“注释”功能时获得的相同数据:我需要能够知道谁是最后一个编写给定代码行的人。
我在互联网上搜索了文档或代码示例,但我能找到的只是诸如以下的建议使用 TFS 命令行工具 https://stackoverflow.com/questions/74526/tfs-annotate-blame-summary-report-for-a-project或者看似不完整代码示例 https://stackoverflow.com/questions/6531408/get-history-of-file-changes-from-tfs-to-implement-custom-blame-behaviour-of-ex.
我不介意在客户端代码中做很多繁重的工作,但似乎没有一种明显的方法来获取有关contents中的代码变更集 https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.changeset.aspx,也不从合并细节 https://msdn.microsoft.com/en-us/library/ff735782.aspx return.
同时我找到了一个执行的工作解决方案Team Foundation 电动工具 https://visualstudiogallery.msdn.microsoft.com/b1ef7eb2-e084-4cb8-9bc7-06c3bad9148f处理并解析其输出:
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();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)