public void GetLastStablePackagesFromIndex() { var index = PackageIndex.Load(PackageIndexes.Select(pi => pi.GetMetadata("FullPath"))); List <ITaskItem> lastStablePackages = new List <ITaskItem>(); 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."); } var latestVersion = (DoNotAllowVersionsFromSameRelease) ? VersionUtility.As2PartVersion(nuGetVersion?.Version) : nuGetVersion?.Version; PackageInfo info; if (index.Packages.TryGetValue(packageId, out info)) { IEnumerable <Version> candidateVersions = (latestVersion == null) ? info.StableVersions : info.StableVersions.Where(sv => VersionUtility.As4PartVersion(sv) < latestVersion); if (candidateVersions.Any()) { lastStablePackages.Add(CreateItem(latestPackage, candidateVersions.Max())); } } } LastStablePackages = lastStablePackages.ToArray(); }
public static Version GetLatestPatchStableVersionForRelease(this IEnumerable <Version> versions, int eraMajorVersion, int eraMinorVersion) { return(versions.Where(v => VersionUtility.As2PartVersion(v) == new Version(eraMajorVersion, eraMinorVersion)) .OrderByDescending(v => v) .FirstOrDefault()); }