c# - 如何获取文件添加到 TFS 的日期

标签 c# command-line tfs

对于特定的分支,我想生成一个文件名列表以及它们最初添加到 TFS 的日期。我真的不介意我用什么方法来获取它,但命令行或 C# 解决方案会很棒。我没有包含任何我尝试过的东西,因为我真的不知道从哪里开始!

我试图得到这样的结果:

Date added     File name
========================
10/02/2015     File1.txt
16/05/2015     File2.txt
19/08/2014     File3.txt

最佳答案

好的,这可以做到,但我不知道这会执行得如何,这可能取决于您的代码库的大小。

在 TFS API 上使用 VersionControlServer 我正在获取所有项目,然后为每个项目查询历史记录以获取第一个变更集,然后获取详细信息:

    void Main()
{
    const String CollectionAddress = "http://tfs:8080/tfs/DefaultCollection";

    using (var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(CollectionAddress)))
    {
        tfs.EnsureAuthenticated();
        var server = tfs.GetService<VersionControlServer>();

        server.GetItems(
            path: "$/Code/",
            version: VersionSpec.Latest,
            recursion: RecursionType.Full,
            deletedState: DeletedState.NonDeleted,
            itemType: ItemType.File)
        .Items
        .Select(
            item =>
                server
                .GetBranchHistory(
                    itemSpecs: new[] { new ItemSpec(item.ServerItem, RecursionType.None), },
                    version: VersionSpec.Latest)
                .Single()
                .Select(
                    a =>
                        new
                        {
                            a.Relative.BranchToItem.ChangesetId,
                            a.Relative.BranchToItem.CheckinDate,
                            a.Relative.BranchToItem.ServerItem,
                        })
                .Single())
        .Dump(5);
    }
}

您可以从 here 下载一个有效的 Linqpad 脚本- 针对 VS2013 对象模型。

关于c# - 如何获取文件添加到 TFS 的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32377778/

相关文章:

c# - 只读自动实现的属性是否可能?

windows - 批量输出到文件包含中文符号

java - 基于命令行参数注入(inject)实现

c# - 通过数据仓库以编程方式检索 TFS "instrumented binaries"的路径信息

TFS - 包含丢失文件的列表

c# - 调试IIS随机疯狂内存使用情况

c# - 如何获取操作系统版本asp.net

c# - 类设计——属性还是参数?

command-line - 如何将命令行参数传递给 gnuplot?

c++ - 在 Visual Studio 中使用 C++ 计划构建