我实现了 TFGet 来下载最新的项目,给出 TFS URL、TFS 路径和本地路径。
当从 TFVC/AzureDevOpsServer 构建定义中选择搁置集时,我需要实现用于取消搁置搁置集的代码。
我使用以下代码来获取用于下载文件和控制要创建或删除的文件夹的项目列表:
ItemSet = VcsRef.GetItems(
TfsPath,
VersionSpec.Latest,
RecursionType.Full,
DeletedState.NonDeleted,
ItemType.File,
true);
我使用以下代码来下载架子集详细信息:
PendingSet[] pendingSets = VcsRef.QueryShelvedChanges("tfget", "userid", null, true);
if (pendingSets.Length <= 0)
{
Console.Error.WriteLine("Unable to retrieve shelveset. Do you have permissions for retrieving this shelveset?");
Environment.Exit(1);
}
else if (pendingSets.Length > 1)
{
Console.Error.WriteLine("Multiple shelvesets match the query arguments.");
Environment.Exit(1);
}
PendingChange[] pendingChanges = pendingSets[0].PendingChanges;
if (pendingChanges.Length <= 0)
{
Console.Error.WriteLine("No pending changes could be found in this shelveset.");
Environment.Exit(1);
}
foreach (PendingChange pendingChange in pendingChanges)
{
Console.WriteLine("Processing pending change:", pendingChange.ToString());
// Only edited files - Nothing to do when file doesn't exist in the shelveset
if (pendingChange.ItemType != ItemType.File ||
!pendingChange.IsEdit ||
pendingChange.IsAdd ||
pendingChange.IsBranch)
{
continue;
}
string relativePath = pendingChange.ToString().Remove(0, TfsPath.Length);
string targetPath = Path.Combine(Local, relativePath.Replace("/", @"\"));
// Download:
pendingChange.DownloadShelvedFile(targetPath);
}
但是,我无法下载搁置集项目...这是正确的方法吗?
您可以尝试使用 REST API 来获取浅层搁置集引用的集合:
Get http://TFS:8080/tfs/DefaultCollection/_apis/tfvc/shelvesets?requestData.includeLinks=true&api-version=3.2-preview