In a dotnet core 2.0 console application, the output of:
Console.WriteLine("Hello World from "+ System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
Is a rather unexpected value:
Hello World from .NET Core 4.6.00001.0
Is there any way to detect .net core 2.0 or later, versus a pre-2.0 .net core platform programmatically? I realize that you probably shouldn't do this in most cases. But in the odd cases where you do need to do this, how would you do this?
Check for the "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2. 0.50727" registry key is present or not. If you need to verify a registry entry then check for the "OCM" (REG_DWORD) entry.
You can see both the SDK versions and runtime versions with the command dotnet --info .
Detect .NET Framework 4.5 and later versions. The version of .NET Framework (4.5 and later) installed on a machine is listed in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full. If the Full subkey is missing, then .NET Framework 4.5 or above isn't installed.
You can use preprocessor symbols that are predefined for you. For example:
var isNetCore2 = false;
#if NETCOREAPP2_0
isNetCore2 = true;
#endif
Console.WriteLine($"Is this .Net Core 2: {isNetCore2}");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With