1- using BenchmarkDotNet . Extensions ;
21using BenchmarkDotNet . Helpers ;
32using Microsoft . Win32 ;
43using Perfolizer . Models ;
5- using System . Runtime . InteropServices ;
64using System . Runtime . Versioning ;
7- using static System . Runtime . InteropServices . RuntimeInformation ;
5+ using System . Runtime . InteropServices ;
6+
7+ #if NETSTANDARD
8+ using BenchmarkDotNet . Extensions ;
9+ #endif
810
911namespace BenchmarkDotNet . Detectors ;
1012
@@ -52,14 +54,21 @@ private static OsInfo ResolveOs()
5254 }
5355 }
5456
55- string operatingSystem = OSDescription ;
56- string operatingSystemVersion = Environment . OSVersion . ToString ( ) ;
5757 if ( IsWindows ( ) )
5858 {
59+ var osVersion = RuntimeInformation . OSDescription . Split ( ' ' ) . LastOrDefault ( ) ?? "" ; // `Microsoft Windows 10.0.26200`
5960 int ? ubr = GetWindowsUbr ( ) ;
60- if ( ubr != null )
61- operatingSystemVersion += $ ".{ ubr } ";
61+ return new OsInfo
62+ {
63+ Name = "Windows" ,
64+ Version = ubr == null
65+ ? osVersion
66+ : $ "{ osVersion } .{ ubr } ",
67+ } ;
6268 }
69+
70+ string operatingSystem = RuntimeInformation . OSDescription ;
71+ string operatingSystemVersion = Environment . OSVersion . ToString ( ) ;
6372 return new OsInfo
6473 {
6574 Name = operatingSystem ,
@@ -115,7 +124,7 @@ internal static bool IsWindows() =>
115124#if NET6_0_OR_GREATER
116125 OperatingSystem . IsWindows ( ) ; // prefer linker-friendly OperatingSystem APIs
117126#else
118- IsOSPlatform ( OSPlatform . Windows ) ;
127+ RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
119128#endif
120129
121130
@@ -124,7 +133,7 @@ internal static bool IsLinux() =>
124133#if NET6_0_OR_GREATER
125134 OperatingSystem . IsLinux ( ) ;
126135#else
127- IsOSPlatform ( OSPlatform . Linux ) ;
136+ RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) ;
128137#endif
129138
130139 [ SupportedOSPlatformGuard ( "macos" ) ]
@@ -133,7 +142,7 @@ internal static bool IsMacOS() =>
133142#if NET6_0_OR_GREATER
134143 OperatingSystem . IsMacOS ( ) ;
135144#else
136- IsOSPlatform ( OSPlatform . OSX ) ;
145+ RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ;
137146#endif
138147
139148 [ SupportedOSPlatformGuard ( "android" ) ]
@@ -159,6 +168,6 @@ internal static bool IsTvOS() =>
159168#if NET6_0_OR_GREATER
160169 OperatingSystem . IsTvOS ( ) ;
161170#else
162- IsOSPlatform ( OSPlatform . Create ( "TVOS" ) ) ;
171+ RuntimeInformation . IsOSPlatform ( OSPlatform . Create ( "TVOS" ) ) ;
163172#endif
164173}
0 commit comments