如何从TFS API流zip文件 [英] How to stream zip file from TFS api

查看:62
本文介绍了如何从TFS API流zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TFS2018 api,并且试图检索解决方案的zip文件,但始终会收到内部服务器错误.

I am using TFS2018 api and I am trying to to retrieve the zip file of a solution but I always get an internal server error.

internal async Task<bool> GetSourceZipFile(string sourceVersionId)
    {
        using (var handler = new HttpClientHandler { Credentials = new NetworkCredential(tfsUser, tfsPass) })
        using (var client = new HttpClient(handler))
        {
            try
            {
                client.BaseAddress = new Uri(tfsServer);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));
                var tempFolder = "c:\\temp\\test";
                tempFolder = HttpUtility.UrlEncode(tempFolder);
                var url = $"DefaultCollection/_api/_versioncontrol/itemContentZipped?path={tempFolder}&version={sourceVersionId}";

                using (var file = await client.GetStreamAsync(url).ConfigureAwait(false))
                using (var memoryStream = new MemoryStream())
                {
                    await file.CopyToAsync(memoryStream);
                    var s = memoryStream.ToArray();
                    var f = s;
                };                 
            }
            catch (Exception ex)
            {
                //  LOGGING                    
            }

            return true;
        }
    }

我不确定zip文件是否由TFS服务器生成.我需要专门设置吗?知道为什么这行不通吗?

I am not sure if the zip file is generated by the TFS server. Do I need to set it specifically? Any idea why this is not working?

推荐答案

您正在将本地文件夹传递给REST API中的path参数.路径应指向源代码管理中的项目(例如:$/MyTeamProject/DEV/SomeCode),而不是本地文件系统.

You're passing in a local folder to the path parameter in the REST API. The path should be to the item in source control (ex: $/MyTeamProject/DEV/SomeCode), not to the local file system.

这篇关于如何从TFS API流zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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