From 2815897b00ffe00a02ac175d3b86a4f584ecbbf2 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Tue, 19 Nov 2024 13:41:00 -0800 Subject: [PATCH 1/2] ILC: Allow OOB reference to upgrade framework assembly --- ...mputeManagedAssembliesToCompileToNative.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Build.Tasks/ComputeManagedAssembliesToCompileToNative.cs b/src/coreclr/tools/aot/ILCompiler.Build.Tasks/ComputeManagedAssembliesToCompileToNative.cs index 60084f4d03d1b..03b35eb712fe7 100644 --- a/src/coreclr/tools/aot/ILCompiler.Build.Tasks/ComputeManagedAssembliesToCompileToNative.cs +++ b/src/coreclr/tools/aot/ILCompiler.Build.Tasks/ComputeManagedAssembliesToCompileToNative.cs @@ -5,6 +5,7 @@ using Microsoft.Build.Utilities; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Reflection.Metadata; using System.Reflection.PortableExecutable; @@ -99,16 +100,20 @@ public override bool Execute() var list = new List(); var assembliesToSkipPublish = new List(); var satelliteAssemblies = new List(); - var nativeAotFrameworkAssembliesToUse = new HashSet(); + var nativeAotFrameworkAssembliesToUse = new Dictionary(); foreach (ITaskItem taskItem in SdkAssemblies) { - nativeAotFrameworkAssembliesToUse.Add(Path.GetFileName(taskItem.ItemSpec)); + var fileName = Path.GetFileName(taskItem.ItemSpec); + if (!nativeAotFrameworkAssembliesToUse.ContainsKey(fileName)) + nativeAotFrameworkAssembliesToUse.Add(fileName, taskItem); } foreach (ITaskItem taskItem in FrameworkAssemblies) { - nativeAotFrameworkAssembliesToUse.Add(Path.GetFileName(taskItem.ItemSpec)); + var fileName = Path.GetFileName(taskItem.ItemSpec); + if (!nativeAotFrameworkAssembliesToUse.ContainsKey(fileName)) + nativeAotFrameworkAssembliesToUse.Add(fileName, taskItem); } foreach (ITaskItem taskItem in Assemblies) @@ -153,8 +158,14 @@ public override bool Execute() // Remove any assemblies whose implementation we want to come from NativeAOT's package. // Currently that's System.Private.* SDK assemblies and a bunch of framework assemblies. - if (nativeAotFrameworkAssembliesToUse.Contains(assemblyFileName)) + if (nativeAotFrameworkAssembliesToUse.TryGetValue(assemblyFileName, out ITaskItem frameworkItem)) { + if (GetFileVersion(itemSpec).CompareTo(GetFileVersion(frameworkItem.ItemSpec)) > 0) + { + // Allow OOB references with higher version to take precedence over the framework assemblies. + list.Add(taskItem); + } + assembliesToSkipPublish.Add(taskItem); continue; } @@ -196,6 +207,12 @@ public override bool Execute() SatelliteAssemblies = satelliteAssemblies.ToArray(); return true; + + static Version GetFileVersion(string path) + { + var versionInfo = FileVersionInfo.GetVersionInfo(path); + return new Version(versionInfo.FileMajorPart, versionInfo.FileMinorPart, versionInfo.FileBuildPart, versionInfo.FilePrivatePart); + } } } } From 822e3178ade783b9027760fa11c68a793599511a Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Wed, 20 Nov 2024 15:36:41 -0800 Subject: [PATCH 2/2] Log error for SPC --- .../ComputeManagedAssembliesToCompileToNative.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Build.Tasks/ComputeManagedAssembliesToCompileToNative.cs b/src/coreclr/tools/aot/ILCompiler.Build.Tasks/ComputeManagedAssembliesToCompileToNative.cs index 03b35eb712fe7..6d278e4b9597a 100644 --- a/src/coreclr/tools/aot/ILCompiler.Build.Tasks/ComputeManagedAssembliesToCompileToNative.cs +++ b/src/coreclr/tools/aot/ILCompiler.Build.Tasks/ComputeManagedAssembliesToCompileToNative.cs @@ -162,8 +162,15 @@ public override bool Execute() { if (GetFileVersion(itemSpec).CompareTo(GetFileVersion(frameworkItem.ItemSpec)) > 0) { - // Allow OOB references with higher version to take precedence over the framework assemblies. - list.Add(taskItem); + if (assemblyFileName == "System.Private.CoreLib.dll") + { + Log.LogError($"Overriding System.Private.CoreLib.dll with a newer version is not supported. Attempted to use {itemSpec} instead of {frameworkItem.ItemSpec}."); + } + else + { + // Allow OOB references with higher version to take precedence over the framework assemblies. + list.Add(taskItem); + } } assembliesToSkipPublish.Add(taskItem);