Detecting .net core 2.0

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?

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

Detecting .net core 2.0, You can use preprocessor symbols that are predefined for you. For example: var isNetCore2 = false; #if NETCOREAPP2_0 isNetCore2 = true;� Core 2.1 and .NET Core 2.2 look for 1.0.x first, then fall back to 1.1.x; .NET Core 3.0 looks for 1.1.x first. This change was made to add support for new cryptographic standards. This change may impact libraries or applications that do platform interop with the OpenSSL-specific interop types in .NET Core.

You can try the code below to get the current .NET version.

Tested on .NET Core 1.1 & 2.0

public static string GetNetCoreVersion()
{
  var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
  var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
  int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
  if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
    return assemblyPath[netCoreAppIndex + 1];
  return null;
}

https://github.com/dotnet/BenchmarkDotNet/issues/448

wangkanai/Detection: ASP.NET Core Detection with , NET Core Detection with Responsive View for identifying details about client device, browser, engine, platform, X please use detection version 2.0 installation. I get results like Microsoft .NET Core 1.1.5 - Windows Server Hosting, Microsoft .NET Core 2.0.3 - Windows Server Hosting or Microsoft ASP.NET Core 2.0.3 - Runtime Package Store (x64) so I use regex matching to extract the 3 digit numeric version from the string. I've attached the powershell script I now have for detecting installed versions of

I didn't find any elegant way of doing this, but if you really need to know which version you're running, you can execute dotnet --version like this:

var psi = new ProcessStartInfo("dotnet", "--version")
{
    RedirectStandardOutput = true
};

var process = Process.Start(psi);
process.WaitForExit();

Console.Write(process.StandardOutput.ReadToEnd()); // writes 2.0.0

Detecting if .Net Core Runtime is installed � Issue #2953 � dotnet , 0, and 2.0.3 on a 64bit system. All the registry entries are being stored in the 32bit section of the SOFTWARE hive 'HKLM:\SOFTWARE\� .NET Core 2.0 downloads for Linux, macOS, and Windows. .NET Core is a cross-platform version of .NET, for building apps that run on Linux, macOS, and Windows.

Does the NUGET Detector only support .NET Core 2.0.0 right now , NET Core 2.0.0 right now? Will 3.1.3 be supported anytime soon? I'm getting this error when I run the� When you migrate your module's functionality to your new middleware, you may find that your code doesn't compile because the HttpContext class has significantly changed in ASP.NET Core. Later on, you'll see how to migrate to the new ASP.NET Core HttpContext. Migrating module insertion into the request pipeline

re: Getting the .NET Core Runtime Version in a Running Application, .NET Core is no different and in this short post I show one way you can There's no direct API that returns a version number like 1.1, 2.0 or 2.1 etc. to be used for feature detection or other application critical comparisons,� Core 3.0 supports .NET Standard 2.1, and by extension, it supports .NET Standard 2.0. By continuing to target .NET Standard 2.0, you will be able to consume it in .NET Core 3.0 applications, but you'll also continue to be able to consume it in .NET Core 2.x applications, .NET Framework 4.6.1+ applications, and Xamarin apps, among others.

.NET Core 2.0 not showing in new project selection, Select ASP.Net Core Web Application. No matter which type of application I choose the only choices I have are 1.0 or 1.1. I have downloaded the dotnet- runtime-� Core is a cross-platform version of .NET, for building apps that run on Linux, macOS, and Windows. This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use.

Comments
  • I could have a Netstandard assembly that gets loaded into both .net core 1.0 and 2.0 right? In which case the above would be sub-optimal.
  • Might be friendlier to return "Unknown" instead of null in the failure case.
  • This may not give you the same version that you are expecting. You system may hold multiple versions of the runtime.