public void GetLastStablePackagesFromStablePackages()
        {
            Dictionary <string, ITaskItem> originalItems      = new Dictionary <string, ITaskItem>();
            Dictionary <string, Version>   latestPackages     = new Dictionary <string, Version>();
            Dictionary <string, Version>   lastStablePackages = new Dictionary <string, Version>();

            foreach (var latestPackage in LatestPackages)
            {
                var packageId = latestPackage.ItemSpec;

                var          versionString = latestPackage.GetMetadata("Version");
                NuGetVersion nuGetVersion  = null;
                if (versionString == null || !NuGetVersion.TryParse(versionString, out nuGetVersion))
                {
                    Log.LogMessage($"Could not parse version {versionString} for LatestPackage {packageId}, will use latest stable.");
                }

                latestPackages[packageId] = nuGetVersion?.Version;
                originalItems[packageId]  = latestPackage;
            }

            foreach (var stablePackage in StablePackages.NullAsEmpty())
            {
                var packageId = stablePackage.ItemSpec;

                Version latestVersion;
                if (!latestPackages.TryGetValue(packageId, out latestVersion))
                {
                    continue;
                }

                var     versionString = stablePackage.GetMetadata("Version");
                Version stableVersion;
                if (versionString == null || !Version.TryParse(versionString, out stableVersion))
                {
                    Log.LogError($"Could not parse version {versionString} for StablePackage {packageId}");
                    continue;
                }
                stableVersion = VersionUtility.As4PartVersion(stableVersion);

                // only consider a stable version less or equal to than current version
                if (latestVersion != null && stableVersion >= latestVersion)
                {
                    continue;
                }

                Version lastStableVersion;
                if (!lastStablePackages.TryGetValue(packageId, out lastStableVersion) || lastStableVersion < stableVersion)
                {
                    lastStablePackages[packageId] = stableVersion;
                }
            }

            LastStablePackages = lastStablePackages.Select(p => CreateItem(originalItems[p.Key], p.Value)).ToArray();
        }
Ejemplo n.º 2
0
        private void LoadStablePackages()
        {
            // build up a map of stable versions
            _stablePackageVersions = new Dictionary <string, Version>();

            foreach (var stablePackage in StablePackages.NullAsEmpty())
            {
                string  stablePackageId = stablePackage.ItemSpec;
                Version newVersion      = ParseAs3PartVersion(stablePackage.GetMetadata("Version"));
                Version existingVersion = null;

                // if we don't have a version or the new version is greater assign it
                if (!_stablePackageVersions.TryGetValue(stablePackageId, out existingVersion) ||
                    (newVersion > existingVersion))
                {
                    _stablePackageVersions[stablePackageId] = newVersion;
                }
            }
        }