gpt4 book ai didi

c# - 从 TFS 获取文件列表

转载 作者:可可西里 更新时间:2023-11-01 08:54:55 32 4
gpt4 key购买 nike

我想弄清楚如何从 TFS 中的特定文件夹(“$/theproject/trunk/setup/”)获取文件列表,而不将它们放在本地文件夹中。

到目前为止,我已经成功连接、创建工作区和工作文件夹:

        var server = RegisteredTfsConnections.GetProjectCollection(new Uri("http://hostname:8080/"));
var projects = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(server);
var versionControl = (VersionControlServer)projects.GetService(typeof(VersionControlServer));

var workspace = versionControl.CreateWorkspace(AppDomain.CurrentDomain.FriendlyName + "-installer", versionControl.AuthorizedUser);
try
{
WorkingFolder folder = new WorkingFolder("$/theproject/trunk/setup/", "C:\\aTempFolder");
workspace.CreateMapping(folder);

//this would get all files to the local folder, right?
//what should I do instead to just get a file list?
workspace.Get();

}
finally
{
workspace.Delete();
}

最佳答案

是这样实现的:

        var server = RegisteredTfsConnections.GetProjectCollection(new Uri("http://hostname:8080/"));
var projects = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(server);
var versionControl = (VersionControlServer)projects.GetService(typeof(VersionControlServer));

var newestDate = DateTime.MinValue;
Item newestItem = null;
var items = versionControl.GetItems("$/theproject/trunk/setup/*.msi");
foreach (var item in items.Items)
{
if (item.ItemType != ItemType.File)
continue;

if (item.CheckinDate > newestDate)
{
newestItem = item;
newestDate = item.CheckinDate;
}
}
newestItem.DownloadFile("C:\\temp\\" + Path.GetFileName(newestItem.ServerItem));

关于c# - 从 TFS 获取文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4757883/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com