private async Task <string> DownloadPackageAsync(NugetPackageSourceInfo packinfo) { string downloadUrl = string.Format(DownloadUrlFormat, packinfo.Id, packinfo.Version); string packageFileName = string.Format(DownloadPackageFileNameFormat, packinfo.Id, packinfo.Version); string outputPackageFileNameFullPath = Path.Combine(_packageTempPath, packageFileName); try { using (HttpClient client = new HttpClient()) { byte[] packageBytes = await client.GetByteArrayAsync(downloadUrl).ConfigureAwait(false); File.WriteAllBytes(outputPackageFileNameFullPath, packageBytes); return(outputPackageFileNameFullPath); } } catch { Console.WriteLine($"Failed to download package {packinfo.Id} {packinfo.Version}"); return(null); } }
private bool TryDownloadPackage(NugetPackageSourceInfo packinfo, out string packageFilePath) { string downloadUrl = string.Format(DownloadUrlFormat, packinfo.Id, packinfo.Version); string packageFileName = string.Format(DownloadPackageFileNameFormat, packinfo.Id, packinfo.Version); string outputPackageFileNameFullPath = Path.Combine(_packageTempPath, packageFileName); try { using (HttpClient client = new HttpClient()) { byte[] packageBytes = client.GetByteArrayAsync(downloadUrl).Result; File.WriteAllBytes(outputPackageFileNameFullPath, packageBytes); } } catch { packageFilePath = null; return(false); } packageFilePath = outputPackageFileNameFullPath; return(true); }