c# - 如何检测 TFS 项目源代码已被修改

标签 c# windows visual-studio-2010 tfs

我在 TFS 中有一个编译成 DLL 的 Visual Studio C# 项目。 我需要知道项目中的任何文件是否在一段时间内被修改过。 像这样:

"from date 01/01/2011 to today,  check if the project has been modified."

在 C# 中使用 TFS API 执行此操作的最佳方法是什么?

我的想法:从 TFS 获取所有项目项,为每个项目检查它的更改历史记录。根据给定的范围周期过滤历史。如果那个时期有变化,那么那个文件被修改了,因此项目也被改变了。这是正确的吗?

是否可以在一段时间内而不是在一系列变更集中进行相同的搜索?例如:

"from changeset 1071 to latest,  check if the project has been modified."

最佳答案

您可以使用 QueryHistory此类问题的方法:

var tfs = new TfsTeamProjectCollection(new Uri(@"http://tfs.example.com:8080"));
var vc = tfs.GetService<VersionControlServer>();

// DateTime fro, to;
var changesets = from cs in vc.QueryHistory(
    "$/YourProject",
    VersionSpec.Latest,
    0,    /* deletion ID, 0 otherwise */
    RecursionType.Full,
    null, /* user, null for all */
    null, /* from changeset, null because these aren't by date */
    null, /* to changeset, null because these aren't by date   */
    Int32.MaxValue, /* get them all */
    false, /* just metadata */
    false /* just the current stuff */
    )
    where cs.CreationDate >= fro && cs.CreationDate <= to
    select cs;

获得变更集列表后,您可以查询它们以获取与之关联的文件。在这一点上,如果你真的真的想排除误报,我会加上 Roslyn支持读取项目和解决方案并使用它来过滤感兴趣的文件名。

关于c# - 如何检测 TFS 项目源代码已被修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13884733/

相关文章:

C#:水平翻转图像

c# - 如果模型类标记为可序列化,则参数值不会映射到 Web API 中

c# - 将纪元转换为日期时间 SQL Server

c# - 使用 Console.WriteLine (C#) 或 printfn (F#) 编写粗体文本?

visual-studio-2010 - 立即窗口, "The expression cannot be evaluated...."

c++ - 如何通过网络将命令从 Windows GUI 发送到 Linux 机器?

c# - 创建自定义谓词

c# - 打开表单时出现 ShowDialog 问题

windows - eventmachine 和外部脚本通过反引号

windows - 检测安静模式