我正在尝试弄清楚如何从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();
}
答案 0 :(得分:16)
这样做:
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));
答案 1 :(得分:9)
试试这个:
ItemSet items = versionControl.GetItems(folder.ServerItem, RecursionType.Full);