diff --git a/nukebuild/ApiDiffHelper.cs b/nukebuild/ApiDiffHelper.cs index 946477d287b..0c094d67d87 100644 --- a/nukebuild/ApiDiffHelper.cs +++ b/nukebuild/ApiDiffHelper.cs @@ -9,6 +9,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Nuke.Common.Tooling; +using Serilog; using static Serilog.Log; public static class ApiDiffHelper @@ -47,13 +48,18 @@ public static async Task GetDiff( var baselineDllPath = await ExtractDll("baseline", baselineDll, tempFolder); var targetTfm = baselineDll.target; - if (s_tfmRedirects.FirstOrDefault(t => baselineDll.target.StartsWith(t.oldTfm)).newTfm is {} newTfm) + var targetDll = targetDlls.FirstOrDefault(e => + e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name); + if (targetDll is null) { - targetTfm = newTfm; + if (s_tfmRedirects.FirstOrDefault(t => baselineDll.target.StartsWith(t.oldTfm)).newTfm is {} newTfm) + { + targetTfm = newTfm; + targetDll = targetDlls.FirstOrDefault(e => + e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name); + } } - var targetDll = targetDlls.FirstOrDefault(e => - e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name); if (targetDll?.entry is null) { throw new InvalidOperationException($"Some assemblies are missing in the new package {packageId}: {baselineDll.entry.Name} for {baselineDll.target}"); @@ -142,16 +148,32 @@ public static async Task ValidatePackage( var baselineDllPath = await ExtractDll("baseline", baselineDll, tempFolder); var targetTfm = baselineDll.target; - if (s_tfmRedirects.FirstOrDefault(t => baselineDll.target.StartsWith(t.oldTfm)).newTfm is {} newTfm) + var targetDll = targetDlls.FirstOrDefault(e => + e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name); + if (targetDll?.entry is null) { - targetTfm = newTfm; + if (s_tfmRedirects.FirstOrDefault(t => baselineDll.target.StartsWith(t.oldTfm)).newTfm is {} newTfm) + { + targetTfm = newTfm; + targetDll = targetDlls.FirstOrDefault(e => + e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name); + } + } + if (targetDll?.entry is null && targetDlls.Count == 1) + { + targetDll = targetDlls.First(); + Warning( + $"Some assemblies are missing in the new package {packageId}: {baselineDll.entry.Name} for {baselineDll.target}." + + $"Resolved: {targetDll.target} ({targetDll.entry.Name})"); } - var targetDll = targetDlls.FirstOrDefault(e => - e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name); - if (targetDll.entry is null) + if (targetDll?.entry is null) { - throw new InvalidOperationException($"Some assemblies are missing in the new package {packageId}: {baselineDll.entry.Name} for {baselineDll.target}"); + var actualTargets = string.Join(", ", + targetDlls.Select(d => $"{d.target} ({baselineDll.entry.Name})")); + throw new InvalidOperationException( + $"Some assemblies are missing in the new package {packageId}: {baselineDll.entry.Name} for {baselineDll.target}." + + $"\r\nActual targets: {actualTargets}."); } var targetDllPath = await ExtractDll("target", targetDll, tempFolder);