我想用Azure DevOps服务API下载一个工件。
在使用C#进行编程时,我选择使用Microsoft.TeamFoundationServer.Client SDK,版本: 16.153.0作为工具。
我肯定我有神器。
但是在我使用BuildHttpClient::GetArtifactContentZipAsync(project: "XXX", buildId: buildid, artifactName: "XXX")之后
得到拉链流。我不同意这样的信息:
The requested version \"5.1\" of the resource is under preview. The -preview flag must be supplied in the api-version for such requests. For example: \"5.1-preview\"
我似乎使用了错误的API版本,但我确实没有看到任何API将此版本设置为“5.1预览”。
有办法解决这个问题吗?还是应该使用较早版本的TFS?
发布于 2020-07-16 08:35:16
我用15.131.1版本的Microsoft.TeamFoundationServer.Client SDK进行了测试,它运行良好,但是尝试16.153.0版本却失败了。

样本代码:
static readonly string TFUrl = "https://dev.azure.com/OrgName/";
static readonly string UserPAT = "PAT";
static void Main(string[] args)
{
try
{
int buildId = xx; // update to an existing build definition id
string artifactName = "drop"; //default artifact name
// string project = "projectName";
ConnectWithPAT(TFUrl, UserPAT);
Stream zipStream = BuildClient.GetArtifactContentZipAsync(buildId, artifactName).Result; //get content
using (FileStream zipFile = new FileStream(@"C:\MySite\test.zip", FileMode.Create))
zipStream.CopyTo(zipFile);
Console.WriteLine("Done");
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
if (ex.InnerException != null) Console.WriteLine("Detailed Info: " + ex.InnerException.Message);
Console.WriteLine("Stack:\n" + ex.StackTrace);
}
}发布于 2020-07-16 11:10:50
谢谢休的回答。也许16.153.0版的SDK有问题。
出于某种原因,我应该使用一个新版本的SDK,所以我选择绕过API,自己下载工件。
首先,利用BuildHttpClient::GetArtifactContentZipAsync实现了一个结构化BuildArtifact对象。然后在BuildArtifact.Resource.DownloadUrl中找到工件的下载链接。最后,我从这个链接中获得资源。
通过这种方式,我应该自己处理一些细节,比如Auth/Httpdownload。但不管怎样,我得到了我想要的。
希望在下一个版本的TFS中工作。
https://stackoverflow.com/questions/62911393
复制相似问题