Browse Source

Switching from RuntimeInformation.IsOSPlatform(XYZ) to OperatingSystem.IsXYZ() (#28233)

* Changed Hosting

* Changed Http

* Changed Identity

* Changed Middleware

* Changed Security

* Changed Servers

* Changed from RuntimeInterop to OperatingSystem

* Revert changes in DotNetMuxer

Co-authored-by: Pranav K <[email protected]>
Stefan Nikolei 5 years ago
parent
commit
7ce071b271
41 changed files with 103 additions and 132 deletions
  1. 2 2
      eng/helix/content/RunTests/ProcessUtil.cs
  2. 1 1
      eng/helix/content/RunTests/TestRunner.cs
  3. 2 2
      src/Components/Components/src/PlatformInfo.cs
  4. 1 1
      src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorage.cs
  5. 5 5
      src/Components/WebAssembly/Server/src/TargetPickerUi.cs
  6. 1 3
      src/Components/WebAssembly/WebAssembly/src/Rendering/RendererRegistry.cs
  7. 1 2
      src/Components/WebAssembly/WebAssembly/src/Services/LazyAssemblyLoader.cs
  8. 1 2
      src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsFileProvider.cs
  9. 4 5
      src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsFileProviderTests.cs
  10. 3 3
      src/Hosting/Server.IntegrationTesting/src/ApplicationPublisher.cs
  11. 2 2
      src/Hosting/Server.IntegrationTesting/src/Common/DotNetCommands.cs
  12. 2 3
      src/Hosting/Server.IntegrationTesting/src/Deployers/NginxDeployer.cs
  13. 1 2
      src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs
  14. 4 4
      src/Hosting/Server.IntegrationTesting/src/TestMatrix.cs
  15. 3 4
      src/Hosting/Server.IntegrationTesting/src/xunit/IISExpressAncmSchema.cs
  16. 2 3
      src/Http/Http/src/BindingAddress.cs
  17. 2 3
      src/Identity/ApiAuthorization.IdentityServer/src/Configuration/ConfigureSigningCredentials.cs
  18. 3 3
      src/Identity/ApiAuthorization.IdentityServer/test/Configuration/ConfigureSigningCredentialsTests.cs
  19. 3 4
      src/Identity/ApiAuthorization.IdentityServer/test/Configuration/SigningKeysLoaderTests.cs
  20. 1 3
      src/Middleware/Diagnostics/test/UnitTests/ExceptionDetailsProviderTest.cs
  21. 2 3
      src/Middleware/SpaServices.Extensions/src/Npm/NodeScriptRunner.cs
  22. 1 2
      src/Middleware/SpaServices.Extensions/test/SpaServicesExtensionsTests.cs
  23. 1 2
      src/Middleware/WebSockets/test/ConformanceTests/Autobahn/Executable.cs
  24. 2 2
      src/Security/Authentication/Negotiate/samples/NegotiateAuthSample/Startup.cs
  25. 2 3
      src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateState.cs
  26. 6 5
      src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs
  27. 1 2
      src/Servers/IIS/IIS/test/Common.FunctionalTests/Infrastructure/RequiresIISAttribute.cs
  28. 1 2
      src/Servers/Kestrel/Core/src/Internal/Certificates/CertificateConfigLoader.cs
  29. 2 3
      src/Servers/Kestrel/Core/src/Middleware/HttpsConnectionMiddleware.cs
  30. 1 2
      src/Servers/Kestrel/Core/test/SniOptionsSelectorTests.cs
  31. 21 21
      src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConstants.cs
  32. 1 1
      src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs
  33. 2 3
      src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/PlatformApis.cs
  34. 3 5
      src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs
  35. 1 2
      src/Servers/Kestrel/shared/test/TestResources.cs
  36. 4 4
      src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs
  37. 3 4
      src/Servers/Kestrel/test/Interop.FunctionalTests/SkipIfChromeUnavailableAttribute.cs
  38. 2 3
      src/Shared/CertificateGeneration/CertificateManager.cs
  39. 1 3
      src/Shared/Process/ProcessExtensions.cs
  40. 1 2
      src/SignalR/clients/ts/FunctionalTests/Program.cs
  41. 1 1
      src/SignalR/server/StackExchangeRedis/test/Docker.cs

+ 2 - 2
eng/helix/content/RunTests/ProcessUtil.cs

@@ -53,7 +53,7 @@ namespace RunTests
         public static Task CaptureDumpAsync(int pid, string dumpFilePath)
         {
             // Skip this on OSX, we know it's unsupported right now
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsMacOS())
             {
                 // Can we capture stacks or do a gcdump instead?
                 return Task.CompletedTask;
@@ -178,7 +178,7 @@ namespace RunTests
                     await CaptureDumpAsync(process.Id, dumpFilePath);
                 }
 
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                if (!OperatingSystem.IsWindows())
                 {
                     sys_kill(process.Id, sig: 2); // SIGINT
 

+ 1 - 1
eng/helix/content/RunTests/TestRunner.cs

@@ -144,7 +144,7 @@ namespace RunTests
                         cancellationToken: new CancellationTokenSource(TimeSpan.FromMinutes(2)).Token);
 
                     // ';' is the path separator on Windows, and ':' on Unix
-                    Options.Path += RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ";" : ":";
+                    Options.Path += OperatingSystem.IsWindows() ? ";" : ":";
                     Options.Path += $"{Environment.GetEnvironmentVariable("DOTNET_CLI_HOME")}/.dotnet/tools";
                     EnvironmentVariables["PATH"] = Options.Path;
                 }

+ 2 - 2
src/Components/Components/src/PlatformInfo.cs

@@ -1,7 +1,7 @@
 // Copyright (c) .NET Foundation. All rights reserved.
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
-using System.Runtime.InteropServices;
+using System;
 
 namespace Microsoft.AspNetCore.Components
 {
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Components
 
         static PlatformInfo()
         {
-            IsWebAssembly = RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"));
+            IsWebAssembly = OperatingSystem.IsBrowser();
         }
     }
 }

+ 1 - 1
src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorage.cs

@@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
         private protected ProtectedBrowserStorage(string storeName, IJSRuntime jsRuntime, IDataProtectionProvider dataProtectionProvider)
         {
             // Performing data protection on the client would give users a false sense of security, so we'll prevent this.
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
+            if (OperatingSystem.IsBrowser())
             {
                 throw new PlatformNotSupportedException($"{GetType()} cannot be used when running in a browser.");
             }

+ 5 - 5
src/Components/WebAssembly/Server/src/TargetPickerUi.cs

@@ -162,17 +162,17 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Server
             var profilePath = Path.Combine(Path.GetTempPath(), "blazor-chrome-debug");
             var debuggerPort = new Uri(_browserHost).Port;
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return $@"<p>Press Win+R and enter the following:</p>
                           <p><strong><code>chrome --remote-debugging-port={debuggerPort} --user-data-dir=""{profilePath}"" {targetApplicationUrl}</code></strong></p>";
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            else if (OperatingSystem.IsLinux())
             {
                 return $@"<p>In a terminal window execute the following:</p>
                           <p><strong><code>google-chrome --remote-debugging-port={debuggerPort} --user-data-dir={profilePath} {targetApplicationUrl}</code></strong></p>";
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 return $@"<p>Execute the following:</p>
                           <p><strong><code>open /Applications/Google\ Chrome.app --args --remote-debugging-port={debuggerPort} --user-data-dir={profilePath} {targetApplicationUrl}</code></strong></p>";
@@ -188,12 +188,12 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Server
             var profilePath = Path.Combine(Path.GetTempPath(), "blazor-edge-debug");
             var debuggerPort = new Uri(_browserHost).Port;
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return $@"<p>Press Win+R and enter the following:</p>
                           <p><strong><code>msedge --remote-debugging-port={debuggerPort} --user-data-dir=""{profilePath}"" --no-first-run {targetApplicationUrl}</code></strong></p>";
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 return $@"<p>In a terminal window execute the following:</p>
                           <p><strong><code>open /Applications/Microsoft\ Edge\ Dev.app --args --remote-debugging-port={debuggerPort} --user-data-dir={profilePath} {targetApplicationUrl}</code></strong></p>";

+ 1 - 3
src/Components/WebAssembly/WebAssembly/src/Rendering/RendererRegistry.cs

@@ -3,7 +3,6 @@
 
 using System;
 using System.Collections.Generic;
-using System.Runtime.InteropServices;
 
 namespace Microsoft.AspNetCore.Components.WebAssembly.Rendering
 {
@@ -19,8 +18,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Rendering
 
         static RendererRegistry()
         {
-            bool _isWebAssembly = RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"));
-            if (_isWebAssembly)
+            if (OperatingSystem.IsBrowser())
             {
                 _renderers = new Dictionary<int, WebAssemblyRenderer>();
             }

+ 1 - 2
src/Components/WebAssembly/WebAssembly/src/Services/LazyAssemblyLoader.cs

@@ -6,7 +6,6 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Reflection;
-using System.Runtime.InteropServices;
 using System.Runtime.Loader;
 using System.Threading.Tasks;
 using Microsoft.JSInterop;
@@ -48,7 +47,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Services
         /// <returns>A list of the loaded <see cref="Assembly"/></returns>
         public async Task<IEnumerable<Assembly>> LoadAssembliesAsync(IEnumerable<string> assembliesToLoad)
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
+            if (OperatingSystem.IsBrowser())
             {
                 return await LoadAssembliesInClientAsync(assembliesToLoad);
             }

+ 1 - 2
src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsFileProvider.cs

@@ -7,7 +7,6 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
 using Microsoft.AspNetCore.Http;
 using Microsoft.Extensions.FileProviders;
 using Microsoft.Extensions.Primitives;
@@ -28,7 +27,7 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
     // <<mylibrarypath>>\wwwroot\** to _content/mylibrary/**
     internal class StaticWebAssetsFileProvider : IFileProvider
     {
-        private static readonly StringComparison FilePathComparison = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
+        private static readonly StringComparison FilePathComparison = OperatingSystem.IsWindows() ?
             StringComparison.OrdinalIgnoreCase :
             StringComparison.Ordinal;
 

+ 4 - 5
src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsFileProviderTests.cs

@@ -3,7 +3,6 @@
 
 using System;
 using System.IO;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
@@ -87,7 +86,7 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
             // Assert
             Assert.Empty(directory);
         }
-        
+
         [Fact]
         public void GetDirectoryContents_HandlersEmptyPath()
         {
@@ -164,7 +163,7 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
         public void GetFileInfo_DoesNotMatch_IncompletePrefixSegments()
         {
             // Arrange
-            var expectedResult = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+            var expectedResult = OperatingSystem.IsWindows();
             var provider = new StaticWebAssetsFileProvider(
                 "_cont",
                 Path.GetDirectoryName(typeof(StaticWebAssetsFileProviderTests).Assembly.Location));
@@ -180,7 +179,7 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
         public void GetFileInfo_Prefix_RespectsOsCaseSensitivity()
         {
             // Arrange
-            var expectedResult = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+            var expectedResult = OperatingSystem.IsWindows();
             var provider = new StaticWebAssetsFileProvider(
                 "_content",
                 Path.GetDirectoryName(typeof(StaticWebAssetsFileProviderTests).Assembly.Location));
@@ -196,7 +195,7 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
         public void GetDirectoryContents_Prefix_RespectsOsCaseSensitivity()
         {
             // Arrange
-            var expectedResult = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+            var expectedResult = OperatingSystem.IsWindows();
             var provider = new StaticWebAssetsFileProvider(
                 "_content",
                 Path.GetDirectoryName(typeof(StaticWebAssetsFileProviderTests).Assembly.Location));

+ 3 - 3
src/Hosting/Server.IntegrationTesting/src/ApplicationPublisher.cs

@@ -106,15 +106,15 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
         private static string GetRuntimeIdentifier(DeploymentParameters deploymentParameters)
         {
             var architecture = deploymentParameters.RuntimeArchitecture;
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return "win-" + architecture;
             }
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            if (OperatingSystem.IsLinux())
             {
                 return "linux-" + architecture;
             }
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsMacOS())
             {
                 return "osx-" + architecture;
             }

+ 2 - 2
src/Hosting/Server.IntegrationTesting/src/Common/DotNetCommands.cs

@@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
         {
             var dotnetDir = DotNetHome;
             var archSpecificDir = Path.Combine(dotnetDir, arch.ToString());
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Directory.Exists(archSpecificDir))
+            if (OperatingSystem.IsWindows() && Directory.Exists(archSpecificDir))
             {
                 dotnetDir = archSpecificDir;
             }
@@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
 
             var dotnetFile = "dotnet";
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 dotnetFile += ".exe";
             }

+ 2 - 3
src/Hosting/Server.IntegrationTesting/src/Deployers/NginxDeployer.cs

@@ -8,7 +8,6 @@ using System.IO;
 using System.Net;
 using System.Net.Http;
 using System.Net.Sockets;
-using System.Runtime.InteropServices;
 using System.Threading.Tasks;
 using Microsoft.AspNetCore.Server.IntegrationTesting.Common;
 using Microsoft.Extensions.Logging;
@@ -42,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
                 if (uri.Port == 0)
                 {
                     var builder = new UriBuilder(uri);
-                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+                    if (OperatingSystem.IsLinux())
                     {
                         // This works with nginx 1.9.1 and later using the reuseport flag, available on Ubuntu 16.04.
                         // Keep it open so nobody else claims the port
@@ -112,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
                 return retVal;
             }
 
-            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (!OperatingSystem.IsWindows())
             {
                 using (var process = new Process
                 {

+ 1 - 2
src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs

@@ -4,7 +4,6 @@
 using System;
 using System.Diagnostics;
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Text.RegularExpressions;
 using System.Threading;
 using System.Threading.Tasks;
@@ -88,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
                 var executableArgs = string.Empty;
                 var workingDirectory = string.Empty;
                 var executableExtension = DeploymentParameters.ApplicationType == ApplicationType.Portable ? ".dll"
-                    : (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "");
+                    : (OperatingSystem.IsWindows() ? ".exe" : "");
 
                 if (DeploymentParameters.PublishApplicationBeforeDeployment)
                 {

+ 4 - 4
src/Hosting/Server.IntegrationTesting/src/TestMatrix.cs

@@ -156,13 +156,13 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
                 case ServerType.IIS:
                 case ServerType.IISExpress:
                 case ServerType.HttpSys:
-                    skip = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+                    skip = !OperatingSystem.IsWindows();
                     break;
                 case ServerType.Kestrel:
                     break;
                 case ServerType.Nginx:
                     // Technically it's possible but we don't test it.
-                    skip = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+                    skip = OperatingSystem.IsWindows();
                     break;
                 default:
                     throw new ArgumentException(server.ToString());
@@ -195,7 +195,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
 
         private static string SkipIfTfmIsNotSupportedOnThisOS(string tfm)
         {
-            if (Tfm.Matches(Tfm.Net461, tfm) && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (Tfm.Matches(Tfm.Net461, tfm) && !OperatingSystem.IsWindows())
             {
                 return "This TFM is not supported on this operating system.";
             }
@@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
             }
 
             // No x86 runtimes available on MacOS or Linux.
-            return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? null : $"No {arch} available for non-Windows systems.";
+            return OperatingSystem.IsWindows() ? null : $"No {arch} available for non-Windows systems.";
         }
 
         private bool IsArchitectureSupportedOnServer(RuntimeArchitecture arch, ServerType server)

+ 3 - 4
src/Hosting/Server.IntegrationTesting/src/xunit/IISExpressAncmSchema.cs

@@ -1,10 +1,9 @@
-// Copyright (c) .NET Foundation. All rights reserved.
+// Copyright (c) .NET Foundation. All rights reserved.
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
 using System;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Xml.Linq;
 
 namespace Microsoft.AspNetCore.Server.IntegrationTesting
@@ -16,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
 
         static IISExpressAncmSchema()
         {
-            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (!OperatingSystem.IsWindows())
             {
                 SkipReason = "IIS Express tests can only be run on Windows";
                 return;
@@ -52,4 +51,4 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
             SkipReason = SupportsInProcessHosting ? null : "IIS Express must be upgraded to support in-process hosting.";
         }
     }
-}
+}

+ 2 - 3
src/Http/Http/src/BindingAddress.cs

@@ -4,7 +4,6 @@
 using System;
 using System.Globalization;
 using System.IO;
-using System.Runtime.InteropServices;
 
 namespace Microsoft.AspNetCore.Http
 {
@@ -55,7 +54,7 @@ namespace Microsoft.AspNetCore.Http
         private static string GetUnixPipePath(string host)
         {
             var unixPipeHostPrefixLength = UnixPipeHostPrefix.Length;
-            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (!OperatingSystem.IsWindows())
             {
                 // "/" character in unix refers to root. Windows has drive letters and volume separator (c:)
                 unixPipeHostPrefixLength--;
@@ -117,7 +116,7 @@ namespace Microsoft.AspNetCore.Http
             else
             {
                 var unixPipeHostPrefixLength = UnixPipeHostPrefix.Length;
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                if (OperatingSystem.IsWindows())
                 {
                     // Windows has drive letters and volume separator (c:)
                     unixPipeHostPrefixLength += 2;

+ 2 - 3
src/Identity/ApiAuthorization.IdentityServer/src/Configuration/ConfigureSigningCredentials.cs

@@ -4,7 +4,6 @@
 using System;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography.X509Certificates;
 using Microsoft.AspNetCore.ApiAuthorization.IdentityServer.Configuration;
 using Microsoft.Extensions.Configuration;
@@ -102,8 +101,8 @@ namespace Microsoft.AspNetCore.ApiAuthorization.IdentityServer
 
         private X509KeyStorageFlags GetStorageFlags(KeyDefinition key)
         {
-            var defaultFlags = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ?
-                UnsafeEphemeralKeySet : (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? X509KeyStorageFlags.PersistKeySet :
+            var defaultFlags = OperatingSystem.IsLinux() ?
+                UnsafeEphemeralKeySet : (OperatingSystem.IsMacOS() ? X509KeyStorageFlags.PersistKeySet :
                 X509KeyStorageFlags.DefaultKeySet);
 
             if (key.StorageFlags == null)

+ 3 - 3
src/Identity/ApiAuthorization.IdentityServer/test/Configuration/ConfigureSigningCredentialsTests.cs

@@ -1,9 +1,9 @@
 // Copyright (c) .NET Foundation. All rights reserved.
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
+using System;
 using System.Collections.Generic;
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography.X509Certificates;
 using Microsoft.AspNetCore.Testing;
 using Microsoft.Extensions.Configuration;
@@ -18,8 +18,8 @@ namespace Microsoft.AspNetCore.ApiAuthorization.IdentityServer
         // due to the fact that is not part of .NET Standard. This value is only used with non-windows
         // platforms (all .NET Core) for which the value is defined on the underlying platform.
         private const X509KeyStorageFlags UnsafeEphemeralKeySet = (X509KeyStorageFlags)32;
-        private static readonly X509KeyStorageFlags DefaultFlags = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ?
-            UnsafeEphemeralKeySet : (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? X509KeyStorageFlags.PersistKeySet :
+        private static readonly X509KeyStorageFlags DefaultFlags = OperatingSystem.IsLinux() ?
+            UnsafeEphemeralKeySet : (OperatingSystem.IsMacOS() ? X509KeyStorageFlags.PersistKeySet :
             X509KeyStorageFlags.DefaultKeySet);
 
         [ConditionalFact]

+ 3 - 4
src/Identity/ApiAuthorization.IdentityServer/test/Configuration/SigningKeysLoaderTests.cs

@@ -1,10 +1,9 @@
-// Copyright (c) .NET Foundation. All rights reserved.
+// Copyright (c) .NET Foundation. All rights reserved.
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
 
 using System;
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography.X509Certificates;
 using Microsoft.AspNetCore.Testing;
 using Xunit;
@@ -17,8 +16,8 @@ namespace Microsoft.AspNetCore.ApiAuthorization.IdentityServer.Configuration
         // due to the fact that is not part of .NET Standard. This value is only used with non-windows
         // platforms (all .NET Core) for which the value is defined on the underlying platform.
         private const X509KeyStorageFlags UnsafeEphemeralKeySet = (X509KeyStorageFlags)32;
-        private static readonly X509KeyStorageFlags DefaultFlags = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ?
-            UnsafeEphemeralKeySet : (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? X509KeyStorageFlags.PersistKeySet :
+        private static readonly X509KeyStorageFlags DefaultFlags = OperatingSystem.IsLinux() ?
+            UnsafeEphemeralKeySet : (OperatingSystem.IsMacOS() ? X509KeyStorageFlags.PersistKeySet :
             X509KeyStorageFlags.DefaultKeySet);
 
         [Fact]

+ 1 - 3
src/Middleware/Diagnostics/test/UnitTests/ExceptionDetailsProviderTest.cs

@@ -6,8 +6,6 @@ using System.Collections.Generic;
 using System.Globalization;
 using System.IO;
 using System.Linq;
-using System.Reflection;
-using System.Runtime.InteropServices;
 using System.Text;
 using Microsoft.AspNetCore.Testing;
 using Microsoft.Extensions.FileProviders;
@@ -28,7 +26,7 @@ namespace Microsoft.Extensions.Internal
                     "TestFiles/SourceFile.txt"
                 };
 
-                if (!(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)))
+                if (!(OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()))
                 {
                     data.Add(@"TestFiles\SourceFile.txt");
                 }

+ 2 - 3
src/Middleware/SpaServices.Extensions/src/Npm/NodeScriptRunner.cs

@@ -4,7 +4,6 @@
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
 using System.Text.RegularExpressions;
 using System.Threading;
 using Microsoft.AspNetCore.NodeServices.Util;
@@ -44,7 +43,7 @@ namespace Microsoft.AspNetCore.NodeServices.Npm
 
             var exeToRun = pkgManagerCommand;
             var completeArguments = $"run {scriptName} -- {arguments ?? string.Empty}";
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 // On Windows, the node executable is a .cmd file, so it can't be executed
                 // directly (except with UseShellExecute=true, but that's no good, because
@@ -76,7 +75,7 @@ namespace Microsoft.AspNetCore.NodeServices.Npm
             StdErr = new EventedStreamReader(_npmProcess.StandardError);
 
             applicationStoppingToken.Register(((IDisposable)this).Dispose);
-            
+
             if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.NodeServices.Npm.NpmStarted"))
             {
                 diagnosticSource.Write(

+ 1 - 2
src/Middleware/SpaServices.Extensions/test/SpaServicesExtensionsTests.cs

@@ -4,7 +4,6 @@
 using System;
 using System.Diagnostics;
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
@@ -119,7 +118,7 @@ namespace Microsoft.AspNetCore.SpaServices.Extensions.Tests
         }
 
         private string GetPlatformSpecificWaitCommand()
-            => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "waitWindows" : "wait";
+            => OperatingSystem.IsWindows() ? "waitWindows" : "wait";
 
         private IApplicationBuilder GetApplicationBuilder(IServiceProvider serviceProvider = null)
         {

+ 1 - 2
src/Middleware/WebSockets/test/ConformanceTests/Autobahn/Executable.cs

@@ -1,7 +1,6 @@
 using System;
 using System.Diagnostics;
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading.Tasks;
 using Microsoft.Extensions.Logging;
@@ -10,7 +9,7 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
 {
     public class Executable
     {
-        private static readonly string _exeSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty;
+        private static readonly string _exeSuffix = OperatingSystem.IsWindows() ? ".exe" : string.Empty;
 
         public string Location { get; }
 

+ 2 - 2
src/Security/Authentication/Negotiate/samples/NegotiateAuthSample/Startup.cs

@@ -1,7 +1,7 @@
 // Copyright (c) .NET Foundation. All rights reserved.
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
-using System.Runtime.InteropServices;
+using System;
 using System.Threading.Tasks;
 using Microsoft.AspNetCore.Authentication.Negotiate;
 using Microsoft.AspNetCore.Builder;
@@ -23,7 +23,7 @@ namespace NegotiateAuthSample
             services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
                 .AddNegotiate(options =>
                 {
-                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+                    if (OperatingSystem.IsLinux())
                     {
                         /*
                         options.EnableLdap("DOMAIN.net");

+ 2 - 3
src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateState.cs

@@ -6,7 +6,6 @@ using System.Linq;
 using System.Net;
 using System.Reflection;
 using System.Runtime.ExceptionServices;
-using System.Runtime.InteropServices;
 using System.Security.Authentication;
 using System.Security.Principal;
 
@@ -49,7 +48,7 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate
             _statusCode = securityStatusType.GetField("ErrorCode");
             _statusException = securityStatusType.GetField("Exception");
 
-            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (!OperatingSystem.IsWindows())
             {
                 var interopType = secAssembly.GetType("Interop", throwOnError: true);
                 var netNativeType = interopType.GetNestedType("NetSecurityNative", BindingFlags.NonPublic | BindingFlags.Static);
@@ -111,7 +110,7 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate
                 // TODO: Remove after corefx changes
                 // The linux implementation always uses InternalError;
                 if (errorCode == SecurityStatusPalErrorCode.InternalError
-                    && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
+                    && !OperatingSystem.IsWindows()
                     && _gssExceptionType.IsInstanceOfType(error))
                 {
                     var majorStatus = (uint)error.HResult;

+ 6 - 5
src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs

@@ -3,12 +3,11 @@
 
 using System;
 using System.IO;
-using System.Runtime.InteropServices;
 using Microsoft.AspNetCore.Builder;
-using Microsoft.Extensions.DependencyInjection;
 using Microsoft.AspNetCore.Hosting.Server;
 using Microsoft.AspNetCore.Server.IIS;
 using Microsoft.AspNetCore.Server.IIS.Core;
+using Microsoft.Extensions.DependencyInjection;
 
 namespace Microsoft.AspNetCore.Hosting
 {
@@ -31,14 +30,15 @@ namespace Microsoft.AspNetCore.Hosting
             }
 
             // Check if in process
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && NativeMethods.IsAspNetCoreModuleLoaded())
+            if (OperatingSystem.IsWindows() && NativeMethods.IsAspNetCoreModuleLoaded())
             {
                 var iisConfigData = NativeMethods.HttpGetApplicationProperties();
                 // Trim trailing slash to be consistent with other servers
                 var contentRoot = iisConfigData.pwzFullApplicationPath.TrimEnd(Path.DirectorySeparatorChar);
                 hostBuilder.UseContentRoot(contentRoot);
                 return hostBuilder.ConfigureServices(
-                    services => {
+                    services =>
+                    {
                         services.AddSingleton(new IISNativeApplication(new NativeSafeHandle(iisConfigData.pNativeApplication)));
                         services.AddSingleton<IServer, IISHttpServer>();
                         services.AddTransient<IISServerAuthenticationHandlerInternal>();
@@ -50,7 +50,8 @@ namespace Microsoft.AspNetCore.Hosting
                             AuthenticationScheme = IISServerDefaults.AuthenticationScheme
                         });
                         services.Configure<IISServerOptions>(
-                            options => {
+                            options =>
+                            {
                                 options.ServerAddresses = iisConfigData.pwzBindings.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                                 options.ForwardWindowsAuthentication = iisConfigData.fWindowsAuthEnabled || iisConfigData.fBasicAuthEnabled;
                                 options.MaxRequestBodySize = iisConfigData.maxRequestBodySize;

+ 1 - 2
src/Servers/IIS/IIS/test/Common.FunctionalTests/Infrastructure/RequiresIISAttribute.cs

@@ -4,7 +4,6 @@
 using System;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Security.Principal;
 using System.Xml.Linq;
 using Microsoft.AspNetCore.Testing;
@@ -39,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
                 return;
             }
 
-            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (!OperatingSystem.IsWindows())
             {
                 _skipReasonStatic = "IIS tests can only be run on Windows";
                 return;

+ 1 - 2
src/Servers/Kestrel/Core/src/Internal/Certificates/CertificateConfigLoader.cs

@@ -4,7 +4,6 @@
 using System;
 using System.Globalization;
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography;
 using System.Security.Cryptography.X509Certificates;
 using Microsoft.AspNetCore.Server.Kestrel.Https;
@@ -56,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Certificates
 
                     if (certificate != null)
                     {
-                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                        if (OperatingSystem.IsWindows())
                         {
                             return PersistKey(certificate);
                         }

+ 2 - 3
src/Servers/Kestrel/Core/src/Middleware/HttpsConnectionMiddleware.cs

@@ -8,7 +8,6 @@ using System.Diagnostics;
 using System.IO;
 using System.IO.Pipelines;
 using System.Net.Security;
-using System.Runtime.InteropServices;
 using System.Security;
 using System.Security.Authentication;
 using System.Security.Cryptography;
@@ -466,7 +465,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
             // This configuration will always fail per-request, preemptively fail it here. See HttpConnection.SelectProtocol().
             if (httpProtocols == HttpProtocols.Http2)
             {
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                if (OperatingSystem.IsMacOS())
                 {
                     throw new NotSupportedException(CoreStrings.Http2NoTlsOsx);
                 }
@@ -486,7 +485,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
 
         private static bool IsWindowsVersionIncompatibleWithHttp2()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 var enableHttp2OnWindows81 = AppContext.TryGetSwitch(EnableWindows81Http2, out var enabled) && enabled;
                 if (Environment.OSVersion.Version < new Version(6, 3) // Missing ALPN support

+ 1 - 2
src/Servers/Kestrel/Core/test/SniOptionsSelectorTests.cs

@@ -6,7 +6,6 @@ using System.Collections.Generic;
 using System.IO.Pipelines;
 using System.Linq;
 using System.Net.Security;
-using System.Runtime.InteropServices;
 using System.Security.Authentication;
 using System.Security.Cryptography.X509Certificates;
 using Microsoft.AspNetCore.Connections;
@@ -661,7 +660,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
 
             CipherSuitesPolicy cipherSuitesPolicy = null;
 
-            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (!OperatingSystem.IsWindows())
             {
                 try
                 {

+ 21 - 21
src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConstants.cs

@@ -1,8 +1,8 @@
 // Copyright (c) .NET Foundation. All rights reserved.
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
+using System;
 using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
 
 namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
 {
@@ -25,15 +25,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
 
         private static int? GetECONNRESET()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return -4077;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            else if (OperatingSystem.IsLinux())
             {
                 return -104;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 return -54;
             }
@@ -42,15 +42,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
 
         private static int? GetEPIPE()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return -4047;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            else if (OperatingSystem.IsLinux())
             {
                 return -32;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 return -32;
             }
@@ -59,15 +59,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
 
         private static int? GetENOTCONN()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return -4053;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            else if (OperatingSystem.IsLinux())
             {
                 return -107;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 return -57;
             }
@@ -76,15 +76,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
 
         private static int? GetEINVAL()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return -4071;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            else if (OperatingSystem.IsLinux())
             {
                 return -22;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 return -22;
             }
@@ -93,15 +93,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
 
         private static int? GetEADDRINUSE()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return -4091;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            else if (OperatingSystem.IsLinux())
             {
                 return -98;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 return -48;
             }
@@ -110,11 +110,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
 
         private static int? GetENOTSUP()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            if (OperatingSystem.IsLinux())
             {
                 return -95;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 return -45;
             }
@@ -123,15 +123,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
 
         private static int? GetECANCELED()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return -4081;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            else if (OperatingSystem.IsLinux())
             {
                 return -125;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 return -89;
             }

+ 1 - 1
src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs

@@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
         private string _pipeName;
         private byte[] _pipeMessage;
         private IntPtr _fileCompletionInfoPtr;
-        private bool _tryDetachFromIOCP = PlatformApis.IsWindows;
+        private bool _tryDetachFromIOCP = OperatingSystem.IsWindows();
 
         // this message is passed to write2 because it must be non-zero-length,
         // but it has no other functional significance

+ 2 - 3
src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/PlatformApis.cs

@@ -3,16 +3,15 @@
 
 using System;
 using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
 using System.Threading;
 
 namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking
 {
     internal static class PlatformApis
     {
-        public static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+        public static bool IsWindows { get; } = OperatingSystem.IsWindows();
 
-        public static bool IsDarwin { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+        public static bool IsDarwin { get; } = OperatingSystem.IsMacOS();
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public static long VolatileRead(ref long value)

+ 3 - 5
src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs

@@ -6,7 +6,6 @@ using System.Buffers;
 using System.Diagnostics;
 using System.IO.Pipelines;
 using System.Net.Sockets;
-using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading.Tasks;
 using Microsoft.AspNetCore.Connections;
@@ -17,7 +16,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
     internal sealed class SocketConnection : TransportConnection
     {
         private static readonly int MinAllocBufferSize = SlabMemoryPool.BlockSize / 2;
-        private static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
 
         private readonly Socket _socket;
         private readonly ISocketsTrace _trace;
@@ -59,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
             // On *nix platforms, Sockets already dispatches to the ThreadPool.
             // Yes, the IOQueues are still used for the PipeSchedulers. This is intentional.
             // https://github.com/aspnet/KestrelHttpServer/issues/2573
-            var awaiterScheduler = IsWindows ? transportScheduler : PipeScheduler.Inline;
+            var awaiterScheduler = OperatingSystem.IsWindows() ? transportScheduler : PipeScheduler.Inline;
 
             var applicationScheduler = PipeScheduler.ThreadPool;
             if (useInlineSchedulers)
@@ -381,7 +379,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
         {
             return errorCode == SocketError.ConnectionReset ||
                    errorCode == SocketError.Shutdown ||
-                   (errorCode == SocketError.ConnectionAborted && IsWindows);
+                   (errorCode == SocketError.ConnectionAborted && OperatingSystem.IsWindows());
         }
 
         private static bool IsConnectionAbortError(SocketError errorCode)
@@ -389,7 +387,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
             // Calling Dispose after ReceiveAsync can cause an "InvalidArgument" error on *nix.
             return errorCode == SocketError.OperationAborted ||
                    errorCode == SocketError.Interrupted ||
-                   (errorCode == SocketError.InvalidArgument && !IsWindows);
+                   (errorCode == SocketError.InvalidArgument && !OperatingSystem.IsWindows());
         }
     }
 }

+ 1 - 2
src/Servers/Kestrel/shared/test/TestResources.cs

@@ -3,7 +3,6 @@
 
 using System;
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography.X509Certificates;
 using System.Threading;
 using Xunit;
@@ -18,7 +17,7 @@ namespace Microsoft.AspNetCore.Testing
         public static string GetCertPath(string name) => Path.Combine(_baseDir, name);
 
         private const int MutexTimeout = 120 * 1000;
-        private static readonly Mutex importPfxMutex = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
+        private static readonly Mutex importPfxMutex = OperatingSystem.IsWindows() ?
             new Mutex(initiallyOwned: false, "Global\\KestrelTests.Certificates.LoadPfxCertificate") :
             null;
 

+ 4 - 4
src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs

@@ -48,17 +48,17 @@ namespace Interop.FunctionalTests
         private static string GetToolLocation()
         {
             var root = Path.Combine(Environment.CurrentDirectory, "h2spec");
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return Path.Combine(root, "windows", "h2spec.exe");
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            else if (OperatingSystem.IsLinux())
             {
                 var toolPath = Path.Combine(root, "linux", "h2spec");
                 chmod755(toolPath);
                 return toolPath;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 var toolPath = Path.Combine(root, "darwin", "h2spec");
                 chmod755(toolPath);
@@ -267,7 +267,7 @@ namespace Interop.FunctionalTests
                     if (node.Attributes["errors"].Value != "0")
                     {
                         // This does not list the individual sub-tests in each section
-                        failures.Add("Test failed: " + node.Attributes["package"].Value + "; "  + node.Attributes["name"].Value);
+                        failures.Add("Test failed: " + node.Attributes["package"].Value + "; " + node.Attributes["name"].Value);
                     }
                     if (node.Attributes["tests"].Value != "0")
                     {

+ 3 - 4
src/Servers/Kestrel/test/Interop.FunctionalTests/SkipIfChromeUnavailableAttribute.cs

@@ -1,9 +1,8 @@
-// Copyright (c) .NET Foundation. All rights reserved.
+// Copyright (c) .NET Foundation. All rights reserved.
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
 using System;
 using System.IO;
-using System.Runtime.InteropServices;
 using Microsoft.AspNetCore.Testing;
 
 namespace Interop.FunctionalTests
@@ -17,11 +16,11 @@ namespace Interop.FunctionalTests
 
         private static string ResolveChromeExecutablePath()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Google", "Chrome", "Application", "chrome.exe");
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            else if (OperatingSystem.IsLinux())
             {
                 return Path.Combine("/usr", "bin", "google-chrome");
             }

+ 2 - 3
src/Shared/CertificateGeneration/CertificateManager.cs

@@ -7,7 +7,6 @@ using System.Diagnostics;
 using System.Diagnostics.Tracing;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography;
 using System.Security.Cryptography.X509Certificates;
 using System.Text;
@@ -30,11 +29,11 @@ namespace Microsoft.AspNetCore.Certificates.Generation
 
         public const int RSAMinimumKeySizeInBits = 2048;
 
-        public static CertificateManager Instance { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
+        public static CertificateManager Instance { get; } = OperatingSystem.IsWindows() ?
 #pragma warning disable CA1416 // Validate platform compatibility
             new WindowsCertificateManager() :
 #pragma warning restore CA1416 // Validate platform compatibility
-            RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
+            OperatingSystem.IsMacOS() ?
                 new MacOSCertificateManager() as CertificateManager :
                 new UnixCertificateManager();
 

+ 1 - 3
src/Shared/Process/ProcessExtensions.cs

@@ -6,13 +6,11 @@ using System.Collections.Generic;
 using System.ComponentModel;
 using System.Diagnostics;
 using System.IO;
-using System.Runtime.InteropServices;
 
 namespace Microsoft.Extensions.Internal
 {
     internal static class ProcessExtensions
     {
-        private static readonly bool _isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
         private static readonly TimeSpan _defaultTimeout = TimeSpan.FromSeconds(30);
 
         public static void KillTree(this Process process) => process.KillTree(_defaultTimeout);
@@ -20,7 +18,7 @@ namespace Microsoft.Extensions.Internal
         public static void KillTree(this Process process, TimeSpan timeout)
         {
             var pid = process.Id;
-            if (_isWindows)
+            if (OperatingSystem.IsWindows())
             {
                 RunProcessAndWaitForExit(
                     "taskkill",

+ 1 - 2
src/SignalR/clients/ts/FunctionalTests/Program.cs

@@ -3,7 +3,6 @@
 
 using System;
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography.X509Certificates;
 using System.Threading.Tasks;
 using Microsoft.AspNetCore.Hosting;
@@ -49,7 +48,7 @@ namespace FunctionalTests
                         options.ConfigureHttpsDefaults(httpsOptions =>
                         {
                             bool useRSA = false;
-                            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                            if (OperatingSystem.IsWindows())
                             {
                                 // Detect Win10+
                                 var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");

+ 1 - 1
src/SignalR/server/StackExchangeRedis/test/Docker.cs

@@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
 {
     public class Docker
     {
-        private static readonly string _exeSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty;
+        private static readonly string _exeSuffix = OperatingSystem.IsWindows() ? ".exe" : string.Empty;
 
         private static readonly string _dockerContainerName = "redisTestContainer";
         private static readonly string _dockerMonitorContainerName = _dockerContainerName + "Monitor";