Skip to content

Conversation

@ds5678
Copy link
Contributor

@ds5678 ds5678 commented Oct 5, 2025

Problem

Discussed in #3580

Solution

@ds5678
Copy link
Contributor Author

ds5678 commented Oct 5, 2025

@CreateAndInject

@ds5678 ds5678 changed the title Support detecting .NET Core 1.0 and 1.1 Support detecting .NET Core 1 Oct 5, 2025
@CreateAndInject
Copy link
Contributor

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);
	}
}

@ds5678
Copy link
Contributor Author

ds5678 commented Oct 5, 2025

@CreateAndInject good now?

@ds5678 ds5678 changed the title Support detecting .NET Core 1 Improve Framework Id detection Oct 5, 2025
@CreateAndInject
Copy link
Contributor

@CreateAndInject good now?

It's worse. I said check netstandard reference in final, but you check System.Runtime in final

@CreateAndInject
Copy link
Contributor

CreateAndInject commented Oct 5, 2025

@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

@ds5678
Copy link
Contributor Author

ds5678 commented Oct 5, 2025

@CreateAndInject good now?

It's worse. I said check netstandard reference in final, but you check System.Runtime in final

Let's say: System.Runtime + netstandard = .NET Core

Why wouldn't it be System.Runtime + netstandard = .NET Standard

@CreateAndInject
Copy link
Contributor

@CreateAndInject good now?

It's worse. I said check netstandard reference in final, but you check System.Runtime in final

Let's 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)

@ds5678
Copy link
Contributor Author

ds5678 commented Oct 5, 2025

Better?

@CreateAndInject
Copy link
Contributor

CreateAndInject commented Oct 5, 2025

Maybe, I'm thinking if we should pick earliest or latest version.

@ds5678
Copy link
Contributor Author

ds5678 commented Oct 5, 2025

Maybe, I'm thinking if we should pick earliest or latest version.

Latest version is what was done before.

@ds5678
Copy link
Contributor Author

ds5678 commented Oct 21, 2025

@siegfriedpammer when you have time, can you review this?

@siegfriedpammer
Copy link
Member

LGTM sorry for the wait!

@siegfriedpammer siegfriedpammer merged commit 2f792f6 into icsharpcode:master Oct 23, 2025
3 of 4 checks passed
@ds5678 ds5678 deleted the net-core-1 branch October 23, 2025 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants