Azure Devops:无法使用TFS客户端库获取工件内容zip [英] Azure Devops: Fail to get artifact content zip with TFS Client lib

查看:51
本文介绍了Azure Devops:无法使用TFS客户端库获取工件内容zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Azure DevOps Services API下载工件.
使用C#编程时,我选择使用 Microsoft.TeamFoundationServer.Client SDK(版本:16.153.0)作为工具.

I want to download an artifact with Azure DevOps Services API.
While programing with C#, I choose to use Microsoft.TeamFoundationServer.Client SDK, Version: 16.153.0 as a tool.

我确定我有神器.
但是在我使用之后 BuildHttpClient :: GetArtifactContentZipAsync(项目:"XXX",buildId:buildid,artifactName:"XXX")
以获得zip流.我收到类似以下消息的异常:
请求的版本\"5.1 \"的资源正在预览中.对于此类请求,必须在api版本中提供-preview标志.例如:\" 5.1-preview \"

似乎我使用了错误的API版本,但我确实没有看到任何API将此版本设置为"5.1-preview".
有办法解决这个问题吗?还是应该使用旧版本的TFS SDK?

It seems I use the wrong version of API, but I really didn't see any API to set this version to "5.1-preview".
Is there a way to solve this problem? Or should I use an older version of TFS SDK?

推荐答案

我使用 Microsoft.TeamFoundationServer.Client SDK的15.131.1版本进行了测试,它运行良好,但尝试使用16.153.0版本,但失败.

I tested with the 15.131.1 version of Microsoft.TeamFoundationServer.Client SDK and it works well , but trying the 16.153.0 version and it failed .

示例代码:

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);
    }
}

这篇关于Azure Devops:无法使用TFS客户端库获取工件内容zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆