public async Task <NuGetVersion> ResolvePackageVersions(string packageName, NuGetVersion referencedVersion, IEnumerable <Uri> sources, VersionRange currentVersionRange, VersionLock versionLock, PrereleaseReporting prerelease, NuGetFramework targetFrameworkName, string projectFilePath, bool isDevelopmentDependency, int olderThanDays) { // Determine whether we are interested in pre-releases bool includePrerelease = referencedVersion.IsPrerelease; if (prerelease == PrereleaseReporting.Always) { includePrerelease = true; } else if (prerelease == PrereleaseReporting.Never) { includePrerelease = false; } string cacheKey = (packageName + "-" + includePrerelease + "-" + targetFrameworkName + "-" + olderThanDays).ToLowerInvariant(); // Get all the available versions var allVersionsRequest = new Lazy <Task <IReadOnlyList <NuGetVersion> > >(() => this._nugetService.GetAllVersions(packageName, sources, includePrerelease, targetFrameworkName, projectFilePath, isDevelopmentDependency, olderThanDays)); var allVersions = await this._cache.GetOrAdd(cacheKey, allVersionsRequest).Value; // Determine the floating behaviour var floatingBehaviour = includePrerelease ? NuGetVersionFloatBehavior.AbsoluteLatest : NuGetVersionFloatBehavior.Major; if (versionLock == VersionLock.Major) { floatingBehaviour = NuGetVersionFloatBehavior.Minor; } if (versionLock == VersionLock.Minor) { floatingBehaviour = NuGetVersionFloatBehavior.Patch; } // Create a new version range for comparison var latestVersionRange = new VersionRange(currentVersionRange, new FloatRange(floatingBehaviour, referencedVersion)); // Use new version range to determine latest version NuGetVersion latestVersion = latestVersionRange.FindBestMatch(allVersions); return(latestVersion); }
public async Task <NuGetVersion> ResolvePackageVersions(string packageName, NuGetVersion referencedVersion, IEnumerable <Uri> sources, VersionRange currentVersionRange, VersionLock versionLock, PrereleaseReporting prerelease, NuGetFramework targetFrameworkName, string projectFilePath, bool isDevelopmentDependency) { return(await ResolvePackageVersions(packageName, referencedVersion, sources, currentVersionRange, versionLock, prerelease, targetFrameworkName, projectFilePath, isDevelopmentDependency, 0)); }
public async Task <(NuGetVersion referencedVersion, NuGetVersion latestVersion)> ResolvePackageVersions( string package, List <Uri> sources, VersionRange currentVersionRange, VersionLock versionLock, PrereleaseReporting prerelease) { // Get all the available versions var allVersions = await _nugetService.GetAllVersions(package, sources); // Resolve the referenced versions NuGetVersion referencedVersion = currentVersionRange.FindBestMatch(allVersions); // Determine whether we are interested in pre-releases bool includePrerelease = referencedVersion.IsPrerelease; if (prerelease == PrereleaseReporting.Always) { includePrerelease = true; } else if (prerelease == PrereleaseReporting.Never) { includePrerelease = false; } // Determine the floating behaviour var floatingBehaviour = includePrerelease ? NuGetVersionFloatBehavior.AbsoluteLatest : NuGetVersionFloatBehavior.Major; if (versionLock == VersionLock.Major) { floatingBehaviour = NuGetVersionFloatBehavior.Minor; } if (versionLock == VersionLock.Minor) { floatingBehaviour = NuGetVersionFloatBehavior.Patch; } // Create a new version range for comparison var latestVersionRange = new VersionRange(currentVersionRange, new FloatRange(floatingBehaviour, referencedVersion)); // Use new version range to determine latest version NuGetVersion latestVersion = latestVersionRange.FindBestMatch(allVersions); return(referencedVersion, latestVersion); }
public async Task ResolvesVersion_Correctly(string current, VersionLock versionLock, PrereleaseReporting prerelease, string latest) { // Arrange // Act var latestVersion = await _nuGetPackageResolutionService.ResolvePackageVersions(packageName, NuGetVersion.Parse(current), new List <Uri>(), VersionRange.Parse(current), versionLock, prerelease, null, null, false); // Assert Assert.Equal(NuGetVersion.Parse(latest), latestVersion); }
public async Task <NuGetVersion> ResolvePackageVersions(string packageName, NuGetVersion referencedVersion, List <Uri> sources, VersionRange currentVersionRange, VersionLock versionLock, PrereleaseReporting prerelease, NuGetFramework targetFrameworkName, string projectFilePath) { // Determine whether we are interested in pre-releases bool includePrerelease = referencedVersion.IsPrerelease; if (prerelease == PrereleaseReporting.Always) { includePrerelease = true; } else if (prerelease == PrereleaseReporting.Never) { includePrerelease = false; } string cacheKey = (packageName + "-" + includePrerelease + "-" + targetFrameworkName).ToLowerInvariant(); if (!_cache.TryGetValue(cacheKey, out var allVersions)) { // Get all the available versions allVersions = await _nugetService.GetAllVersions(packageName, sources, includePrerelease, targetFrameworkName, projectFilePath); _cache.Add(cacheKey, allVersions); } // Determine the floating behaviour var floatingBehaviour = includePrerelease ? NuGetVersionFloatBehavior.AbsoluteLatest : NuGetVersionFloatBehavior.Major; if (versionLock == VersionLock.Major) { floatingBehaviour = NuGetVersionFloatBehavior.Minor; } if (versionLock == VersionLock.Minor) { floatingBehaviour = NuGetVersionFloatBehavior.Patch; } // Create a new version range for comparison var latestVersionRange = new VersionRange(currentVersionRange, new FloatRange(floatingBehaviour, referencedVersion)); // Use new version range to determine latest version NuGetVersion latestVersion = latestVersionRange.FindBestMatch(allVersions); return(latestVersion); }