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(); }
private void ValidateIndex() { if (SkipIndexCheck) { return; } if (PackageIndexes == null || PackageIndexes.Length == 0) { return; } var index = PackageIndex.Load(PackageIndexes.Select(pi => pi.GetMetadata("FullPath"))); PackageInfo info; if (!index.Packages.TryGetValue(PackageId, out info)) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} is missing an entry for package {PackageId}. Please run /t:UpdatePackageIndex on this project to commit an update."); return; } var allDlls = _report.Targets.Values.SelectMany(t => t.CompileAssets.NullAsEmpty().Concat(t.RuntimeAssets.NullAsEmpty())); var allAssemblies = allDlls.Where(f => f.Version != null); var assemblyVersions = new HashSet <Version>(allAssemblies.Select(f => VersionUtility.As4PartVersion(f.Version))); var thisPackageVersion = VersionUtility.As3PartVersion(NuGetVersion.Parse(PackageVersion).Version); foreach (var fileVersion in assemblyVersions) { Version packageVersion; // determine if we're missing a mapping for this package if (!info.AssemblyVersionInPackageVersion.TryGetValue(fileVersion, out packageVersion)) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} is missing an assembly version entry for {fileVersion} for package {PackageId}. Please run /t:UpdatePackageIndex on this project to commit an update."); } else { // determine if we have a mapping for an unstable package and that unstable package is not this one if (!info.StableVersions.Contains(packageVersion) && packageVersion != thisPackageVersion) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} indicates that assembly version {fileVersion} is contained in non-stable package version {packageVersion} which differs from this package version {thisPackageVersion}."); } } } var orphanedAssemblyVersions = info.AssemblyVersionInPackageVersion .Where(pair => pair.Value == thisPackageVersion && !assemblyVersions.Contains(pair.Key)) .Select(pair => pair.Key); if (orphanedAssemblyVersions.Any()) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} is has an assembly version entry(s) for {String.Join(", ", orphanedAssemblyVersions)} which are no longer in package {PackageId}. Please run /t:UpdatePackageIndex on this project to commit an update."); } // if no assemblies are present in this package nor were ever present if (assemblyVersions.Count == 0 && info.AssemblyVersionInPackageVersion.Count == 0) { // if in the native module map if (index.ModulesToPackages.Values.Any(p => p.Equals(PackageId))) { // ensure the baseline is set if (info.BaselineVersion != thisPackageVersion) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} is missing an baseline entry(s) for native module {PackageId}. Please run /t:UpdatePackageIndex on this project to commit an update."); } } else { // not in the native module map, see if any of the modules in this package are present // (with a different package, as would be the case for runtime-specific packages) var moduleNames = allDlls.Select(d => Path.GetFileNameWithoutExtension(d.LocalPath)); var missingModuleNames = moduleNames.Where(m => !index.ModulesToPackages.ContainsKey(m)); if (missingModuleNames.Any()) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} is missing ModulesToPackages entry(s) for {String.Join(", ", missingModuleNames)} to package {PackageId}. Please add a an entry for the appropriate package."); } } } }
private void ValidateIndex() { if (SkipIndexCheck) { return; } if (PackageIndexes == null || PackageIndexes.Length == 0) { return; } PackageIndex.Current.Merge(PackageIndexes.Select(pi => pi.GetMetadata("FullPath"))); PackageInfo info; if (!PackageIndex.Current.Packages.TryGetValue(PackageId, out info)) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} is missing an entry for package {PackageId}. Please run /t:UpdatePackageIndex on this project to commit an update."); return; } var thisPackageFiles = _validateFiles[PackageId]; var refFiles = thisPackageFiles.Where(f => f.TargetPath.StartsWith("ref/", StringComparison.OrdinalIgnoreCase)).Where(r => !NuGetAssetResolver.IsPlaceholder(r.TargetPath)); if (!refFiles.Any()) { refFiles = thisPackageFiles.Where(f => f.TargetPath.StartsWith("lib/", StringComparison.OrdinalIgnoreCase)); } var thisPackageVersion = VersionUtility.As3PartVersion(NuGetVersion.Parse(PackageVersion).Version); var refFileVersions = new HashSet <Version>(refFiles.Where(r => r.Version != null).Select(r => VersionUtility.As4PartVersion(r.Version))); foreach (var refFileVersion in refFileVersions) { Version refPackageVersion; // determine if we're missing a mapping for this package if (!info.AssemblyVersionInPackageVersion.TryGetValue(refFileVersion, out refPackageVersion)) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} is missing an assembly version entry for {refFileVersion} for package {PackageId}. Please run /t:UpdatePackageIndex on this project to commit an update."); } else { // determine if we have a mapping for an unstable package and that unstable package is not this one if (!info.StableVersions.Contains(refPackageVersion) && refPackageVersion != thisPackageVersion) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} indicates that assembly version {refFileVersion} is contained in non-stable package version {refPackageVersion} which differs from this package version {thisPackageVersion}."); } } } var orphanedAssemblyVersions = info.AssemblyVersionInPackageVersion .Where(pair => pair.Value == thisPackageVersion && !refFileVersions.Contains(pair.Key)) .Select(pair => pair.Key); if (orphanedAssemblyVersions.Any()) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} is has an assembly version entry(s) for {String.Join(", ", orphanedAssemblyVersions)} which are no longer in package {PackageId}. Please run /t:UpdatePackageIndex on this project to commit an update."); } }
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 = nuGetVersion?.Version; PackageInfo info; if (index.Packages.TryGetValue(packageId, out info)) { var 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(); }
private void ValidateIndex() { if (SkipIndexCheck) { return; } if (PackageIndexes == null || PackageIndexes.Length == 0) { return; } PackageIndex.Current.Merge(PackageIndexes.Select(pi => pi.GetMetadata("FullPath"))); PackageInfo info; if (!PackageIndex.Current.Packages.TryGetValue(PackageId, out info)) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} is missing an entry for package {PackageId}. Please run /t:UpdatePackageIndex on this project to commit an update."); return; } var thisPackageFiles = _validateFiles[PackageId]; var refFiles = thisPackageFiles.Where(f => f.TargetPath.StartsWith("ref/", StringComparison.OrdinalIgnoreCase)); if (!refFiles.Any()) { refFiles = thisPackageFiles.Where(f => f.TargetPath.StartsWith("lib/", StringComparison.OrdinalIgnoreCase)); } foreach (var refFileVersion in refFiles.Where(r => r.Version != null).Select(r => VersionUtility.As4PartVersion(r.Version)).Distinct()) { if (!info.AssemblyVersionInPackageVersion.ContainsKey(refFileVersion)) { Log.LogError($"PackageIndex from {String.Join(", ", PackageIndexes.Select(i => i.ItemSpec))} is missing an assembly version entry for {refFileVersion} for package {PackageId}. Please run /t:UpdatePackageIndex on this project to commit an update."); } } }