Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何使用TfvcHttpClient类下载项目_Git_C# 4.0_Azure Devops - Fatal编程技术网

Git 如何使用TfvcHttpClient类下载项目

Git 如何使用TfvcHttpClient类下载项目,git,c#-4.0,azure-devops,Git,C# 4.0,Azure Devops,对于我们的自动化需求之一,我们需要下载一组git存储库,这些存储库在VisualStudio Online的团队项目下提供。 我们正在使用Microsoft.TeamFoundation.SourceControl.WebApi下可用的类来检索存储库详细信息,我们可以在这里取得成功。现在我们需要将每个存储库下载到本地机器上。我考虑使用TfvcHttpClient.DownloadItemZipAsync将整个存储库作为zip文件下载。下面是我用来下载存储库的代码片段 private async

对于我们的自动化需求之一,我们需要下载一组git存储库,这些存储库在VisualStudio Online的团队项目下提供。 我们正在使用Microsoft.TeamFoundation.SourceControl.WebApi下可用的类来检索存储库详细信息,我们可以在这里取得成功。现在我们需要将每个存储库下载到本地机器上。我考虑使用
TfvcHttpClient.DownloadItemZipAsync
将整个存储库作为zip文件下载。下面是我用来下载存储库的代码片段

private async Task<Stream> DownloadRepo(Guid repositoryId, string repoUrl)
        {
            System.Threading.CancellationToken cancelToken = new System.Threading.CancellationToken();
            TfvcHttpClient client = new TfvcHttpClient(new Uri("https://myproject.visualstudio.com/DefaultCollection/"), Credentials);
            var file = await client.DownloadItemZipAsync("$/", new TfvcVersionDescriptor()
                {
                    VersionOption = TfvcVersionOption.None,
                    VersionType = TfvcVersionType.Latest
                }, cancelToken);

            return file;
        }
private async Task DownloadRepo(Guid repositoryId,string repoUrl)
{
System.Threading.CancellationToken cancelToken=新的System.Threading.CancellationToken();
TfvcHttpClient客户端=新TfvcHttpClient(新Uri(“https://myproject.visualstudio.com/DefaultCollection/(a)全权证书;
var file=await client.DownloadItemZipAsync(“$/”,新的TfvcVersionDescriptor()
{
VersionOption=TfvcVersionOption.None,
VersionType=TfvcVersionType.Latest
},取消代币);
返回文件;
}
但在这里,我不清楚如何传递TeamProjectId和存储库Id,以便api可以下载存储库详细信息


非常感谢您的帮助。

我编写了一个工具来管理TFS中的Git存储库,即。您需要从Collection对象中获取
GitRepositoryService
,并通过可用存储库的信息进行询问


如果您能分叉并扩展我的代码以支持您的场景,那就太好了,这样其他人可能会受益。

感谢Giulio的回复。但我在查询了所有Git存储库后使用REST调用解决了这个问题。