private static async Task DownloadPackages(string[] sources) { var d = new NuGetPackageDownloader.NuGetDownloader(Framework, DownloadDirectory, includePrerelease: IncludePrerelease, recursive: Recursive, extract: Extract, sources: sources); Stopwatch sw = Stopwatch.StartNew(); try { if (DownloadInParallel) { ParallelDownload(d, sw); } else { await SynchronousDownload(d, sw); } } finally { Console.WriteLine(sw.Elapsed); } }
private static void Main(string[] args) { var downloader = new NuGetPackageDownloader.NuGetDownloader(TargetFramework.NetCoreApp3_1); ParserResult <object> parseResult = new Parser(with => with.HelpWriter = null) .ParseArguments <DownloadCommand, ExtractCommand, VersionCommand>(args); parseResult .WithParsed <DownloadCommand>(async opts => { if (Enum.TryParse(opts.Framework.Trim(), true, out TargetFramework framework)) { await downloader.DownloadPackageAsync(opts.Name.Trim()); } }) .WithParsed <ExtractCommand>(async opts => { if (Enum.TryParse(opts.Framework.Trim(), true, out TargetFramework framework)) { await downloader.DownloadPackageAsync(opts.Name.Trim()); } }) .WithParsed <VersionCommand>(async opts => { var metadata = new NuGetMetadata(); var versions = await metadata.GetPackageVersionsAsync(opts.Name.Trim()); foreach (string version in versions) { Console.WriteLine(version); } }) .WithNotParsed(errs => HelpContent.DisplayHelp(parseResult, errs)); }
private static void ParallelDownload(NuGetPackageDownloader.NuGetDownloader downloader, Stopwatch sw) { Parallel.ForEach(Packages, (package) => { downloader.DownloadPackageAsync(package).GetAwaiter().GetResult(); Console.WriteLine($"[{sw.Elapsed}] Downloading {package}..."); }); }
private static async Task SynchronousDownload(NuGetPackageDownloader.NuGetDownloader downloader, Stopwatch sw) { foreach (string package in Packages) { Console.WriteLine($"[{sw.Elapsed}] Downloading {package}..."); await downloader.DownloadPackageAsync(package); } }
private static async Task GetPackageDependencies(string[] sources) { var deps = new NuGetPackageDownloader.NuGetDownloader(Framework, DownloadDirectory, recursive: true, sources: sources); foreach (string package in Packages) { Console.WriteLine($"{package} dependencies"); var dependencies = await deps.GetPackageDependenciesAsync(package); foreach (NuGetPackage dependency in dependencies) { Console.WriteLine($" {dependency.Id} ({dependency.Version})"); } } }