Here is the difference assembly.CodeBase
is obsolete according to Micrsoft, the proper usage for nw is assembly.Location
Last active
March 15, 2024 22:22
-
-
Save karenpayneoregon/81b514e3ad6fa2c7e335962f79a24ebd to your computer and use it in GitHub Desktop.
Get .NET Core runtime version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string FrameworkRuntimeVersion() | |
{ | |
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly; | |
var path = assembly.Location.Split(new[] { '/', '\\' }, | |
StringSplitOptions.RemoveEmptyEntries); | |
var index = Array.IndexOf(path, "Microsoft.NETCore.App"); | |
return index > 0 && index < path.Length - 2 ? path[index + 1] : null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment