-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Improve Framework Id detection #3581
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
Conversation
|
Seems we should check netstandard reference in the final, I think a .NET Core app reference a .NET Standard assembly will produce both System.Runtime and netstandard reference. My code based on dnlib: public static void GetTargetFramework(this ModuleDef module, out string framework, out Version version, out string profile) {
if (module.Assembly != null && module.Assembly.TryGetOriginalTargetFrameworkAttribute(out framework, out version, out profile))
return;
profile = null;
if (module.IsClr10) {
framework = ".NETFramework";
version = new Version(1, 0, 0, 0);
}
else if (module.IsClr11) {
framework = ".NETFramework";
version = new Version(1, 1, 0, 0);
}
else if (module.IsClr20) {
framework = ".NETFramework";
var asmRefs = module.GetAssemblyRefs().Cast<IAssembly>();
if (module.Assembly != null)
asmRefs = asmRefs.Append(module.Assembly);
if (asmRefs.Any(x => x.IsSystemAssembly() && x.Version == new Version(3, 5, 0, 0)))
version = new Version(3, 5, 0, 0);
else if (asmRefs.Any(x => x.IsSystemAssembly() && x.Version == new Version(3, 0, 0, 0)))
version = new Version(3, 0, 0, 0);
else
version = new Version(2, 0, 0, 0);
}
else if ((module.GetAssemblyRef("System.Runtime") ?? module.GetAssemblyRef("System.Private.CoreLib")) is { } netcore && netcore.Version >= new Version(4, 1, 0, 0)) {
framework = ".NETCoreApp";
version = (netcore.Version.Major, netcore.Version.Minor, netcore.Version.Build) switch {
(4, 1, 0) => new Version(1, 0, 0, 0),
(4, 2, 0) => new Version(2, 0, 0, 0),
(4, 2, 1) => new Version(2, 1, 0, 0),
(4, 2, 2) => new Version(3, 1, 0, 0),
_ => netcore.Version,
};
}
else if (module.GetAssemblyRef("netstandard") is { } netstandard && module.GetAssemblyRef("mscorlib") is null) {
framework = ".NETStandard";
version = netstandard.Version;
}
else {
framework = ".NETFramework";
version = new Version(4, 0, 0, 0);
}
} |
|
@CreateAndInject good now? |
It's worse. I said check netstandard reference in final, but you check System.Runtime in final |
Let me say: System.Runtime + netstandard = .NET Core |
Why wouldn't it be System.Runtime + netstandard = .NET Standard |
.NET Standard project should not reference specificed framework(.NET Core/ .NET Framework) |
|
Better? |
|
Maybe, I'm thinking if we should pick earliest or latest version. |
Latest version is what was done before. |
|
@siegfriedpammer when you have time, can you review this? |
|
LGTM sorry for the wait! |
Problem
Discussed in #3580
Solution