Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/9.0-staging] ILC: Allow OOB reference to upgrade framework assembly #110058

Open
wants to merge 2 commits into
base: release/9.0-staging
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,16 +100,20 @@ public override bool Execute()
var list = new List<ITaskItem>();
var assembliesToSkipPublish = new List<ITaskItem>();
var satelliteAssemblies = new List<ITaskItem>();
var nativeAotFrameworkAssembliesToUse = new HashSet<string>();
var nativeAotFrameworkAssembliesToUse = new Dictionary<string, ITaskItem>();

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)
Expand Down Expand Up @@ -153,8 +158,21 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflict resolution also checks assembly version first, but I don't think our current packages have any case where we might ship an older assembly version with newer file version (EG: newer package from lower servicing band). We used to - which is why that check in conflict resolution was required - but a single file version check should be good enough now since I think we give every assembly the same major.minor file and assembly version. Does that sound right @ViktorHofer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only exception that I know of in dotnet/runtime is System.Runtime.Serialization.Formatters

OOB 9.0.0 package assembly:

image

inbox 9.0.0 assembly:

image

There might be other packages, not sure. The above don't probably doesn't matter because only the inbox assembly has the difference, not the packaged-up assembly.

{
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);
continue;
}
Expand Down Expand Up @@ -196,6 +214,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);
}
}
}
}
Loading