|
2 | 2 | #pragma warning disable MA0047 // Declare types in namespaces |
3 | 3 | #pragma warning disable MA0048 // File name must match type name |
4 | 4 | using System.IO.Compression; |
| 5 | +using System.Net.Http; |
5 | 6 | using System.Reflection; |
6 | 7 | using System.Text.Json; |
7 | 8 | using Meziantou.Polyfill.Generator; |
8 | 9 | using Microsoft.CodeAnalysis.CSharp; |
9 | 10 | using Microsoft.CodeAnalysis; |
10 | 11 | using Meziantou.Framework; |
11 | 12 | using System.Text.RegularExpressions; |
12 | | -using NuGet.Common; |
13 | | -using NuGet.Protocol; |
14 | | -using NuGet.Protocol.Core.Types; |
15 | | -using NuGet.Versioning; |
16 | 13 |
|
17 | 14 | // Reference doesn't contains internal types which may be needed |
18 | 15 | // So, use the runtime types to get all available types and methods |
@@ -663,31 +660,20 @@ static async Task EnsurePackagesDownloadedAsync(string nugetPackagesPath, (strin |
663 | 660 |
|
664 | 661 | Console.WriteLine($"Downloading {packagesToDownload.Length} missing reference assembly package(s)..."); |
665 | 662 |
|
666 | | - using var cacheContext = new SourceCacheContext(); |
667 | | - var repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json"); |
668 | | - var resource = await repository.GetResourceAsync<FindPackageByIdResource>(); |
669 | | - |
| 663 | + using var httpClient = new HttpClient(); |
670 | 664 | foreach (var (packageId, version) in packagesToDownload) |
671 | 665 | { |
| 666 | + var url = $"https://api.nuget.org/v3-flatcontainer/{packageId}/{version}/{packageId}.{version}.nupkg"; |
672 | 667 | Console.WriteLine($" Downloading {packageId}@{version}..."); |
673 | 668 |
|
674 | | - using var packageStream = new MemoryStream(); |
675 | | - var success = await resource.CopyNupkgToStreamAsync( |
676 | | - packageId, |
677 | | - new NuGetVersion(version), |
678 | | - packageStream, |
679 | | - cacheContext, |
680 | | - NullLogger.Instance, |
681 | | - CancellationToken.None); |
| 669 | + using var response = await httpClient.GetAsync(url); |
| 670 | + response.EnsureSuccessStatusCode(); |
682 | 671 |
|
683 | | - if (!success) |
684 | | - throw new InvalidOperationException($"Failed to download NuGet package {packageId}@{version}"); |
| 672 | + using var packageStream = await response.Content.ReadAsStreamAsync(); |
| 673 | + using var archive = new ZipArchive(packageStream, ZipArchiveMode.Read); |
685 | 674 |
|
686 | 675 | var packageDir = Path.Combine(nugetPackagesPath, packageId, version); |
687 | | - packageStream.Seek(0, SeekOrigin.Begin); |
688 | | - |
689 | 676 | Directory.CreateDirectory(packageDir); |
690 | | - using var archive = new ZipArchive(packageStream, ZipArchiveMode.Read); |
691 | 677 | archive.ExtractToDirectory(packageDir); |
692 | 678 |
|
693 | 679 | Console.WriteLine($" Installed {packageId}@{version}"); |
|
0 commit comments