private void UpdateFromValues(PackageIndex index, string id, NuGetVersion version, IEnumerable <Version> assemblyVersions, IEnumerable <string> dllNames) { PackageInfo info = GetOrCreatePackageInfo(index, id); var packageVersion = VersionUtility.As3PartVersion(version.Version); // if we have a stable version, add it to the stable versions list if (!version.IsPrerelease) { info.StableVersions.Add(packageVersion); } var assmVersions = new HashSet <Version>(assemblyVersions.NullAsEmpty().Where(v => v != null)); // add any new assembly versions info.AddAssemblyVersionsInPackage(assmVersions, packageVersion); // try to find an identity package to also add a mapping in the case this is a runtime package if (id.StartsWith("runtime.")) { foreach (var dllName in dllNames) { PackageInfo identityInfo; if (index.Packages.TryGetValue(dllName, out identityInfo)) { identityInfo.AddAssemblyVersionsInPackage(assmVersions, packageVersion); } } } // remove any assembly mappings which claim to be in this package version, but aren't in the assemblyList var orphanedAssemblyVersions = info.AssemblyVersionInPackageVersion .Where(pair => pair.Value == packageVersion && !assmVersions.Contains(pair.Key)) .Select(pair => pair.Key); if (orphanedAssemblyVersions.Any()) { // make sure these aren't coming from a runtime package. var runtimeAssemblyVersions = index.Packages .Where(p => p.Key.StartsWith("runtime.") && p.Key.EndsWith(id)) .SelectMany(p => p.Value.AssemblyVersionInPackageVersion) .Where(pair => pair.Value == packageVersion) .Select(pair => pair.Key); orphanedAssemblyVersions = orphanedAssemblyVersions.Except(runtimeAssemblyVersions); } foreach (var orphanedAssemblyVersion in orphanedAssemblyVersions.ToArray()) { info.AssemblyVersionInPackageVersion.Remove(orphanedAssemblyVersion); } // if no assemblies are present in this package nor were ever present if (assmVersions.Count == 0 && info.AssemblyVersionInPackageVersion.Count == 0) { // if in the native module map if (index.ModulesToPackages.Values.Any(p => p.Equals(id))) { // ensure the baseline is set info.BaselineVersion = packageVersion; } } }
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 UpdateFromValues(PackageIndex index, string id, NuGetVersion version, IEnumerable <Version> assemblyVersions, IEnumerable <string> dllNames) { PackageInfo info = GetOrCreatePackageInfo(index, id); if (UpdateStablePackageInfo) { try { IEnumerable <Version> allStableVersions = NuGetUtility.GetAllVersionsForPackageId(id, includePrerelease: false, includeUnlisted: false, Log, CancellationToken.None); info.StableVersions.AddRange(allStableVersions); } catch (NuGetProtocolException) { Log.LogWarning("Failed fetching stable nuget package versions from one or more of your feeds. Make sure you are connected to the internet and that all your feeds are reachable."); } } var packageVersion = VersionUtility.As3PartVersion(version.Version); // if we have a stable version, add it to the stable versions list if (!version.IsPrerelease) { info.StableVersions.Add(packageVersion); } var assmVersions = new HashSet <Version>(assemblyVersions.NullAsEmpty().Where(v => v != null)); // add any new assembly versions info.AddAssemblyVersionsInPackage(assmVersions, packageVersion); // try to find an identity package to also add a mapping in the case this is a runtime package if (id.StartsWith("runtime.")) { foreach (var dllName in dllNames) { PackageInfo identityInfo; if (index.Packages.TryGetValue(dllName, out identityInfo)) { identityInfo.AddAssemblyVersionsInPackage(assmVersions, packageVersion); } } } // remove any assembly mappings which claim to be in this package version, but aren't in the assemblyList var orphanedAssemblyVersions = info.AssemblyVersionInPackageVersion .Where(pair => pair.Value == packageVersion && !assmVersions.Contains(pair.Key)) .Select(pair => pair.Key); if (orphanedAssemblyVersions.Any()) { // make sure these aren't coming from a runtime package. var runtimeAssemblyVersions = index.Packages .Where(p => p.Key.StartsWith("runtime.") && p.Key.EndsWith(id)) .SelectMany(p => p.Value.AssemblyVersionInPackageVersion) .Where(pair => pair.Value == packageVersion) .Select(pair => pair.Key); orphanedAssemblyVersions = orphanedAssemblyVersions.Except(runtimeAssemblyVersions); } foreach (var orphanedAssemblyVersion in orphanedAssemblyVersions.ToArray()) { info.AssemblyVersionInPackageVersion.Remove(orphanedAssemblyVersion); } // if no assemblies are present in this package nor were ever present if (assmVersions.Count == 0 && info.AssemblyVersionInPackageVersion.Count == 0) { // if in the native module map if (index.ModulesToPackages.Values.Any(p => p.Equals(id))) { // ensure the baseline is set info.BaselineVersion = packageVersion; } } }