public async Task <ImmutableArray <SemanticVersion> > GetAllVersions( NuGetPackageId packageId, string?nuGetSource = default, string?nugetConfig = default, bool allowPreRelease = false, HttpClient?httpClient = default, ILogger?logger = default, CancellationToken cancellationToken = default) { bool clientOwned = httpClient is null; var allVersions = await GetAllVersionsFromApiInternalAsync( packageId, nuGetSource, nugetConfig, allowPreRelease, httpClient ?? new HttpClient(), logger ?? Logger.None, cancellationToken); if (clientOwned) { httpClient?.Dispose(); } return(allVersions); }
public async Task <SemanticVersion?> GetLatestVersionAsync( NuGetPackageId packageId, string nugetExePath, string?nuGetSource = null, bool allowPreRelease = false, string prefix = DefaultPrefixPackageId, int?timeoutInSeconds = 30, string?nugetConfig = null, bool?adaptiveEnabled = null) { var allVersions = await GetAllVersionsAsync( packageId, nugetExePath, nuGetSource, allowPreRelease, prefix, timeoutInSeconds, nugetConfig, adaptiveEnabled).ConfigureAwait(continueOnCapturedContext: false); if (allVersions.Length == 0) { return(null); } return(allVersions.Max()); }
public static NuGetPackageInstallResult Failed([NotNull] NuGetPackageId nugetPackageId) { if (nugetPackageId == null) { throw new ArgumentNullException(nameof(nugetPackageId)); } return(new NuGetPackageInstallResult(nugetPackageId, null, null)); }
public NuGetPackageInstallResult( [NotNull] NuGetPackageId nugetPackageNuGetPackageId, SemanticVersion?semanticVersion, DirectoryInfo?packageDirectory) { NuGetPackageId = nugetPackageNuGetPackageId ?? throw new ArgumentNullException(nameof(nugetPackageNuGetPackageId)); SemanticVersion = semanticVersion; PackageDirectory = packageDirectory; }
public async Task <ImmutableArray <SemanticVersion> > GetAllVersionsAsync( NuGetPackageId packageId, string?nugetExePath = null, string?nuGetSource = null, bool allowPreRelease = false, string?prefix = DefaultPrefixPackageId, int?timeoutInSeconds = 30, string?nugetConfig = null, bool?adaptiveEnabled = null, bool useCli = false) { if (!useCli) { using var client = new HttpClient(); using var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutInSeconds ?? 30)); return(await GetAllVersionsFromApiInternalAsync( packageId, nuGetSource, nugetConfig, allowPreRelease, client, Logger.None, tokenSource.Token)); } return(await GetAllVersionsInternalAsync( packageId, nugetExePath, nuGetSource, allowPreRelease, prefix, timeoutInSeconds, nugetConfig, adaptiveEnabled : adaptiveEnabled)); }
public NuGetPackage(NuGetPackageId nugetPackageId, NuGetPackageVersion?nugetPackageVersion = null) { NuGetPackageId = nugetPackageId ?? throw new ArgumentNullException(nameof(nugetPackageId)); NuGetPackageVersion = nugetPackageVersion ?? NuGetPackageVersion.LatestAvailable; }
private async Task <ImmutableArray <SemanticVersion> > GetAllVersionsFromApiInternalAsync( NuGetPackageId packageId, string?nuGetSource, string?nugetConfig, bool allowPreRelease, HttpClient httpClient, ILogger logger, CancellationToken cancellationToken) { ISettings?settings = null; if (!string.IsNullOrWhiteSpace(nugetConfig)) { var fileInfo = new FileInfo(nugetConfig); settings = Settings.LoadSpecificSettings(fileInfo.Directory !.FullName, fileInfo.Name); } string?currentDirectory = Directory.GetCurrentDirectory(); settings ??= Settings.LoadDefaultSettings( currentDirectory, configFileName: null, new XPlatMachineWideSetting()); var sources = SettingsUtility.GetEnabledSources(settings).ToArray(); var cache = new SourceCacheContext(); NuGet.Common.ILogger nugetLogger = GetLogger(logger); var semanticVersions = new HashSet <SemanticVersion>(); foreach (var packageSource in sources) { if (!string.IsNullOrWhiteSpace(nuGetSource) && !packageSource.Name.Equals(nuGetSource, StringComparison.OrdinalIgnoreCase)) { continue; } SourceRepository repository; if (packageSource.IsHttp) { bool isV3Feed; if (packageSource.ProtocolVersion == 3) { isV3Feed = true; } else { isV3Feed = await IsV3Feed(packageSource, httpClient, HttpMethod.Head, cancellationToken); } repository = isV3Feed ? Repository.Factory.GetCoreV3(packageSource.SourceUri.ToString()) : Repository.Factory.GetCoreV2(packageSource); } else { repository = Repository.Factory.GetCoreV2(packageSource); } if (sources.Length == 1 && sources[0].Credentials is { })