File tree Expand file tree Collapse file tree 1 file changed +13
-19
lines changed Expand file tree Collapse file tree 1 file changed +13
-19
lines changed Original file line number Diff line number Diff line change @@ -351,30 +351,24 @@ private static string GetOSType()
351
351
352
352
private static string GetOSVersion ( ITrace2 trace2 )
353
353
{
354
+ //
355
+ // Since .NET 5 we can use Environment.OSVersion because it was updated to
356
+ // return the correct version on Windows & macOS, rather than the manifested
357
+ // version for Windows or the kernel version for macOS.
358
+ // https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/5.0/environment-osversion-returns-correct-version
359
+ //
360
+ // However, we still need to use the old method for Windows on .NET Framework
361
+ // and call into the Win32 API to get the correct version (regardless of app
362
+ // compatibility settings).
363
+ #if NETFRAMEWORK
354
364
if ( IsWindows ( ) && RtlGetVersionEx ( out RTL_OSVERSIONINFOEX osvi ) == 0 )
355
365
{
356
366
return $ "{ osvi . dwMajorVersion } .{ osvi . dwMinorVersion } (build { osvi . dwBuildNumber } )";
357
367
}
358
-
359
- if ( IsMacOS ( ) )
368
+ #endif
369
+ if ( IsWindows ( ) || IsMacOS ( ) )
360
370
{
361
- var psi = new ProcessStartInfo
362
- {
363
- FileName = "/usr/bin/sw_vers" ,
364
- Arguments = "-productVersion" ,
365
- RedirectStandardOutput = true
366
- } ;
367
-
368
- using ( var swvers = new ChildProcess ( trace2 , psi ) )
369
- {
370
- swvers . Start ( Trace2ProcessClass . Other ) ;
371
- swvers . WaitForExit ( ) ;
372
-
373
- if ( swvers . ExitCode == 0 )
374
- {
375
- return swvers . StandardOutput . ReadToEnd ( ) . Trim ( ) ;
376
- }
377
- }
371
+ return Environment . OSVersion . VersionString ;
378
372
}
379
373
380
374
if ( IsLinux ( ) )
You can’t perform that action at this time.
0 commit comments