-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
AppContext.TargetFrameworkName differs between CoreRT and CoreCLR #23101
Comments
@AlexGhiondea is this a type you have context on? It's the Core equivalent of Quirking? Should we take this change? |
This would be very useful, as there's no current reliable way at runtime to get the currently executing framework and version. Created a new issue for this https://github.com/dotnet/corefx/issues/23197 |
@danmosemsft the On CoreCLR we don't return null. We actually look at AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName. On CoreCLR I am not sure we want to read the value from the main exe as a) there might not be an entry assembly and b) the host can choose to put a different TFM on the default AppDomain. /cc @jkotas |
We should return value from the TargetFrameworkName attribute in CoreCLR, I think. It is one line change - copy the implementation from CoreRT:
|
@jkotas I tried this change. But still the value being returned in the Corefx Tests is null. Currently Debugging to get more info |
This is because xunit.console.netcore.exe is the entrypoint assembly for your test and it is missing the attribute. I assume it does work when you do "dotnet.exe myapp.dll" as myapp.dll is the entrypoint assembly and should have it. |
dotnet/coreclr#13266 (review)
In CoreCLR, AppContext.TargetFrameworkName will always return null. On CoreRT/ProjectN, it will return attribute value from main exe https://github.com/dotnet/corert/blob/ff7eba504516fa0bc0a50357ad559c19b45d1d51/src/System.Private.CoreLib/src/System/AppContext.cs#L45
If we are OK with updating CoreCLR, we return
return Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName;
from AppDomainSetup.TargetFrameworkNamethis will cause AppContext to parse ".NETCoreApp,Version=v2.0" and have an identifier and version instead of empty/null as it currently has and I don't know what that will do downstream.
The text was updated successfully, but these errors were encountered: