internal static string GetRuntimeVersion() { #if CLASSIC if (IsMono()) { var monoRuntimeType = Type.GetType("Mono.Runtime"); var monoDisplayName = monoRuntimeType?.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); if (monoDisplayName != null) { string version = monoDisplayName.Invoke(null, null)?.ToString(); if (version != null) { int bracket1 = version.IndexOf('('), bracket2 = version.IndexOf(')'); if (bracket1 != -1 && bracket2 != -1) { string comment = version.Substring(bracket1 + 1, bracket2 - bracket1 - 1); var commentParts = comment.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (commentParts.Length > 2) { version = version.Substring(0, bracket1) + "(" + commentParts[0] + " " + commentParts[1] + ")"; } } } return("Mono " + version); } } string frameworkVersion = CsProjClassicNetToolchain.GetCurrentNetFrameworkVersion(); string clrVersion = System.Environment.Version.ToString(); return($".NET Framework {frameworkVersion} (CLR {clrVersion})"); #else var runtimeVersion = GetNetCoreVersion() ?? "?"; var coreclrAssemblyInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(object).GetTypeInfo().Assembly.Location); var corefxAssemblyInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(System.Text.RegularExpressions.Regex).GetTypeInfo().Assembly.Location); return($".NET Core {runtimeVersion} (CoreCLR {coreclrAssemblyInfo.FileVersion}, CoreFX {corefxAssemblyInfo.FileVersion})"); #endif }
internal static string GetRuntimeVersion() { #if CLASSIC if (IsMono()) { var monoRuntimeType = Type.GetType("Mono.Runtime"); var monoDisplayName = monoRuntimeType?.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); if (monoDisplayName != null) { string version = monoDisplayName.Invoke(null, null)?.ToString(); if (version != null) { int bracket1 = version.IndexOf('('), bracket2 = version.IndexOf(')'); if (bracket1 != -1 && bracket2 != -1) { string comment = version.Substring(bracket1 + 1, bracket2 - bracket1 - 1); var commentParts = comment.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (commentParts.Length > 2) { version = version.Substring(0, bracket1) + "(" + commentParts[0] + " " + commentParts[1] + ")"; } } } return("Mono " + version); } } string frameworkVersion = CsProjClassicNetToolchain.GetCurrentNetFrameworkVersion(); string clrVersion = System.Environment.Version.ToString(); return($".NET Framework {frameworkVersion} (CLR {clrVersion})"); #else var runtimeVersion = GetNetCoreVersion() ?? "?"; string frameworkVersion = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.Replace(".NET Core ", ""); return($".NET Core {runtimeVersion} (Framework {frameworkVersion})"); #endif }