C# 通过VSTS REST客户端API下载多个git项目内容的有效方法

C# 通过VSTS REST客户端API下载多个git项目内容的有效方法,c#,azure-devops,C#,Azure Devops,我有400个项目的集合,可以使用VSTS REST客户端API从存储库下载 但是我不明白为什么我必须打第二个电话才能得到物品的内容?这背后的原因是什么 我的代码在下载内容时有没有一种有效的方法 以下是代码: .. code here to set up the connection etc.. //get the items var gitItems = gitClient.GetItemsAsync(repo.Id, scopePath: "/DemoWebApp/Source/DemoTe

我有400个项目的集合,可以使用VSTS REST客户端API从存储库下载

但是我不明白为什么我必须打第二个电话才能得到物品的内容?这背后的原因是什么

我的代码在下载内容时有没有一种有效的方法

以下是代码:

.. code here to set up the connection etc..

//get the items
var gitItems = gitClient.GetItemsAsync(repo.Id, scopePath: "/DemoWebApp/Source/DemoTests/",
    download: false, includeContentMetadata: true, includeLinks: true, recursionLevel: VersionControlRecursionType.Full).Result.Where(x => x.IsFolder == false);

foreach(var gitItem in gitItems)
{
    var gitItemUrl = gitItem.Url.Split('?')[0];

    var fileName = Path.GetFileName(gitItemUrl);

    var fileInfo = new FileInfo(gitItem.Path);
    var directoryInfo = fileInfo.Directory;
    var subDirectory = directoryInfo.Name;

    //get the item's content which is a Stream
    var itemContent = gitClient.GetItemContentAsync(repo.Id.ToString(), gitItem.Path).Result;

    //working directory where to store the files.
    var workingDirectory = string.Format("C:\\Download\\{0}", subDirectory);

    //only create the directory if it doesnt exist
    if (!Directory.Exists(workingDirectory))
    {
        Directory.CreateDirectory(workingDirectory);
    }

    //Actually process the files and generate the output
    using (FileStream fs = new FileStream(string.Format(workingDirectory + "\\{0}",fileName), FileMode.Create, FileAccess.Write))
    {
        itemContent.CopyTo(fileStream);
        itemContent.Close();
    }
}
根据文件->

URI参数 包容性内容

布尔值

设置为true以在请求json时包含项内容。默认值为false。

GetItemsAsync()
Method无法获取项目的内容,并且它也没有“includeContent”参数

如果要下载项目,请使用
GetItemZipAsync()
方法。它将下载您在计算机上指定为zip的路径下的所有项目

        Stream res = ghc.GetItemZipAsync("RepoId", "Path").Result;
        using (FileStream fs = new FileStream(string.Format(@"D:\a\1.zip"), FileMode.Create, FileAccess.Write))
        {
            res.CopyTo(fs);
            res.Close();
        }