diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs index fb01823790..a11fb0270c 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs @@ -67,7 +67,7 @@ namespace Microsoft.PowerShell.Commands protected override void BeginProcessing() { var args = "-P now"; - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + if (Platform.IsMacOS) { args = "now"; } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UnblockFile.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UnblockFile.cs index 5c297ed86d..6633a66f96 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UnblockFile.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/UnblockFile.cs @@ -137,7 +137,7 @@ namespace Microsoft.PowerShell.Commands } } #else - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (Platform.IsLinux) { string errorMessage = UnblockFileStrings.LinuxNotSupported; Exception e = new PlatformNotSupportedException(errorMessage); diff --git a/src/Microsoft.PowerShell.GlobalTool.Shim/GlobalToolShim.cs b/src/Microsoft.PowerShell.GlobalTool.Shim/GlobalToolShim.cs index 3b253582b6..33675e30b4 100644 --- a/src/Microsoft.PowerShell.GlobalTool.Shim/GlobalToolShim.cs +++ b/src/Microsoft.PowerShell.GlobalTool.Shim/GlobalToolShim.cs @@ -26,7 +26,7 @@ namespace Microsoft.PowerShell.GlobalTool.Shim public static int Main(string[] args) { var currentPath = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location).Directory.FullName; - var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + var isWindows = Platform.IsWindows; string platformFolder = isWindows ? WinFolderName : UnixFolderName; diff --git a/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs b/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs index 43e6ad17eb..fad311df98 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs @@ -540,17 +540,17 @@ namespace System.Management.Automation ext = string.Empty; var processArch = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (Platform.IsWindows) { folderName = "win-" + processArch; ext = ".dll"; } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + else if (Platform.IsLinux) { folderName = "linux-" + processArch; ext = ".so"; } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if (Platform.IsMacOS) { folderName = "osx-x64"; ext = ".dylib"; diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index 45be8721b7..1986c4c63b 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -22,7 +22,7 @@ namespace System.Management.Automation { get { - return RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + return OperatingSystem.IsLinux(); } } @@ -33,7 +33,7 @@ namespace System.Management.Automation { get { - return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + return OperatingSystem.IsMacOS(); } } @@ -44,7 +44,7 @@ namespace System.Management.Automation { get { - return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + return OperatingSystem.IsWindows(); } } diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index c57ed5ed2d..15d742e40b 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -469,9 +469,7 @@ namespace Microsoft.PowerShell.Commands #if !UNIX // The placeholder mode management APIs Rtl(Set|Query)(Process|Thread)PlaceholderCompatibilityMode // are only supported starting with Windows 10 version 1803 (build 17134) - Version minBuildForPlaceHolderAPIs = new Version(10, 0, 17134, 0); - - if (Environment.OSVersion.Version >= minBuildForPlaceHolderAPIs) + if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134, 0)) { // let's be safe, don't change the PlaceHolderCompatibilityMode if the current one is not what we expect if (NativeMethods.RtlQueryProcessPlaceholderCompatibilityMode() == NativeMethods.PHCM_DISGUISE_PLACEHOLDER) @@ -2724,8 +2722,7 @@ namespace Microsoft.PowerShell.Commands // The new AllowUnprivilegedCreate is only available on Win10 build 14972 or newer var flags = isDirectory ? NativeMethods.SymbolicLinkFlags.Directory : NativeMethods.SymbolicLinkFlags.File; - Version minBuildOfDeveloperMode = new Version(10, 0, 14972, 0); - if (Environment.OSVersion.Version >= minBuildOfDeveloperMode) + if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 14972, 0)) { flags |= NativeMethods.SymbolicLinkFlags.AllowUnprivilegedCreate; } diff --git a/src/System.Management.Automation/security/SecuritySupport.cs b/src/System.Management.Automation/security/SecuritySupport.cs index 7b5087411e..6321d301ce 100644 --- a/src/System.Management.Automation/security/SecuritySupport.cs +++ b/src/System.Management.Automation/security/SecuritySupport.cs @@ -1213,7 +1213,7 @@ namespace System.Management.Automation storeCU.Open(OpenFlags.ReadOnly); X509Certificate2Collection storeCerts = storeCU.Certificates; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (Platform.IsWindows) { using (var storeLM = new X509Store("my", StoreLocation.LocalMachine)) { diff --git a/src/powershell/Program.cs b/src/powershell/Program.cs index 3fee683618..d085db22b9 100644 --- a/src/powershell/Program.cs +++ b/src/powershell/Program.cs @@ -5,6 +5,7 @@ using System; using System.IO; +using System.Management.Automation; using System.Reflection; using System.Runtime.InteropServices; @@ -89,7 +90,7 @@ namespace Microsoft.PowerShell return; } - bool isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + bool isLinux = Platform.IsLinux; // The first byte (ASCII char) of the name of this process, used to detect '-' for login byte procNameFirstByte; diff --git a/test/perf/benchmarks/Engine.ScriptBlock.cs b/test/perf/benchmarks/Engine.ScriptBlock.cs index ad373dd5f9..1f9ac98942 100644 --- a/test/perf/benchmarks/Engine.ScriptBlock.cs +++ b/test/perf/benchmarks/Engine.ScriptBlock.cs @@ -36,7 +36,7 @@ namespace Engine yield return @"[System.IO.Path]::HasExtension('')"; // Test on COM method invocation. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (Platform.IsWindows) { yield return @"$sh=New-Object -ComObject Shell.Application; $sh.Namespace('c:\')"; yield return @"$fs=New-Object -ComObject scripting.filesystemobject; $fs.Drives"; @@ -54,7 +54,7 @@ namespace Engine // believe that there is no need to run many ops in each interation. However, the subsequent runs // of this method is much faster than the first run, and this causes 'MinIterationTime' warnings // to our benchmarks and make the benchmark results not reliable. - // Calling this method once in 'GlobalSetup' is a workaround. + // Calling this method once in 'GlobalSetup' is a workaround. // See https://github.com/dotnet/BenchmarkDotNet/issues/837#issuecomment-828600157 scriptBlock.Invoke(); }