From de2374b59a920745ecc71e505ea30d228edc2462 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Wed, 26 Apr 2023 04:05:31 -0700 Subject: [PATCH] Fix Mono detection in namer (#855) --- src/Verify/Naming/Namer.cs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Verify/Naming/Namer.cs b/src/Verify/Naming/Namer.cs index f789fd4e04..4f8ea75a3c 100644 --- a/src/Verify/Naming/Namer.cs +++ b/src/Verify/Naming/Namer.cs @@ -234,12 +234,6 @@ internal static (string runtime, Version Version) GetRuntimeAndVersion() return ("Core", new(3, 0)); #elif NETCOREAPP3_1 return ("Core", new(3, 1)); -#elif NET462 - return ("Net", new(4, 6)); -#elif NET472 - return ("Net", new(4, 7)); -#elif NET48 - return ("Net", new(4, 8)); #elif NET5_0 return ("DotNet", new(5, 0)); #elif NET6_0 @@ -248,6 +242,27 @@ internal static (string runtime, Version Version) GetRuntimeAndVersion() return ("DotNet", new(7, 0)); #elif NET8_0 return ("DotNet", new(8, 0)); +#elif NETFRAMEWORK + + // Mono can only be detected at runtime, and will use .NET Framework targets, so we have to check it first. + if (RuntimeInformation.FrameworkDescription.StartsWith("Mono", StringComparison.OrdinalIgnoreCase)) + { + return ("Mono", Environment.Version.MajorMinor()); + } + + // It's one of the .NET Framework versions we're explicitly targeting. +#if NET462 + return ("Net", new(4, 6)); +#elif NET472 + return ("Net", new(4, 7)); +#elif NET48 + return ("Net", new(4, 8)); +#endif + + // It's only possible to get here if we've started compiling Verify for a new .NET Framework target + // and forgot to add it to the list above. Thus "not implemented" is appropriate. + throw new NotImplementedException(); + #else var description = RuntimeInformation.FrameworkDescription;