【问题标题】:How to get a list of files from TFS from a specified date?如何从指定日期从 TFS 获取文件列表?
【发布时间】:2015-10-04 14:47:00
【问题描述】:

我在 TFS 中有一个 Visual Studio 2010 C# 项目。我想从 TFS 下载某个日期以上的所有文件。

在 C# 中使用 TFS API 执行此操作的最佳方法是什么? 我所做的:从 TFS 获取所有项目项目,为每个项目检查签入日期并下载它。不幸的是,我有很多这些文件,下载它们然后按日期过滤它们需要很长时间。

我的代码:

var tfs = RegisteredTfsConnections.GetProjectCollection(new Uri("MyTfsUri"));
var projects = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfs);
var versionControl = (VersionControlServer)projects.GetService(typeof(VersionControlServer));
ItemSet itemsSqlScripts = versionControl.GetItems("Path in TFS", RecursionType.Full);

foreach (var item in itemsSqlScripts.Items)
{
                if (item.CheckinDate > date)
                {
                    item.DownloadFile("C:\\SqlScripts\\" + Path.GetFileName(item.ServerItem));
                }
}

我想要这样的东西:

ItemSet itemsSqlScripts = versionControl.GetItems("Path in TFS", RecursionType.Full, and here parameter filter -> for example new DateTime(2015, 5, 1, 0, 0, 0);

我观看并阅读了:

tfs.GetService<VersionControlServer>().QueryHistory(...)

但我不知道如何使用此功能来做我想做的事情:(

请帮忙

【问题讨论】:

    标签: windows visual-studio-2010 c#-4.0 tfs


    【解决方案1】:

    你可以这样做:

    DateTime targetDate = DateTime.Now.AddDays(-1);
    string downloadLocation;
    
    var changes = versionControl.QueryHistory(
                "$/MyProject",
                VersionSpec.Latest,
                0,
                RecursionType.Full,
                null,
                new DateVersionSpec(targetDate),
                VersionSpec.Latest,
                int.MaxValue,
                true,
                false);
    
    foreach (Changeset changeset in changes)
    {
        foreach (var change in changeset.Changes.Where(c => c.Item.ItemType == ItemType.File))
        {
            change.Item.DownloadFile(downloadLocation + change.Item.ServerItem.Substring(2));
        }                                
    }
    

    【讨论】:

      猜你喜欢
      • 2012-12-16
      • 2014-08-19
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 2018-10-09
      • 1970-01-01
      • 2012-02-08
      相关资源
      最近更新 更多