我正在使用VSTS API 2018来基于sourcepath和sourceversion检索压缩的解决方案文件。要获取sourceVersion,我使用teamproject名称和buildId对其进行查询。
问题是我还需要获取所有依赖项目。问题是,如何才能为压缩解决方案中的所有相关项目检索teamProject和buildId,以便我也可以为其获取压缩解决方案文件。这是获取压缩解决方案文件的代码:
internal async Task<string> GetSolutionFromSource(string sourcePath, string sourceVersion)
{
var solutionFile = string.Empty;
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 url = $"DefaultCollection/_api/_versioncontrol/itemContentZipped?path={sourcePath}&version={sourceVersion}";
var solution = sourcePath.Substring(sourcePath.LastIndexOf('/') + 1);
var directory = CreateDirectory(solution, sourcePath);
var zipFile = string.Empty;
log.Debug("TFS: streaming zipped solution ");
zipFile = $"{directory}\\solution.zip";
using (var file = await client.GetStreamAsync(url).ConfigureAwait(false))
using (var fs = new FileStream(zipFile, FileMode.OpenOrCreate))
{
await file.CopyToAsync(fs);
fs.Flush();
}
log.Debug("TFS: Extracting zipped solution to a temp folder");
ExtractZip(zipFile, directory);
solutionFile = FindSolutionFile(solution, directory);
log.Debug("TFS: Found solution file at " + solutionFile);
}
catch (Exception ex)
{
log.Error(ex);
throw ex;
}
return solutionFile;
}
}