public async Task <NuGetVersion> ResolvePackageVersions(string packageName, NuGetVersion referencedVersion, IEnumerable <Uri> sources, VersionRange currentVersionRange,
                                                                VersionLock versionLock, PrereleaseReporting prerelease, NuGetFramework targetFrameworkName, string projectFilePath, bool isDevelopmentDependency)
        {
            // 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, isDevelopmentDependency);

                _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);
        }
Esempio n. 2
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);
        }