diff --git a/eng/helix/content/RunTests/ProcessUtil.cs b/eng/helix/content/RunTests/ProcessUtil.cs index 2cd13c856d79..8ac00bf829c3 100644 --- a/eng/helix/content/RunTests/ProcessUtil.cs +++ b/eng/helix/content/RunTests/ProcessUtil.cs @@ -53,7 +53,7 @@ public static Task CaptureDumpAsync(int pid) 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 @@ public static async Task RunAsync( await CaptureDumpAsync(process.Id, dumpFilePath); } - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { sys_kill(process.Id, sig: 2); // SIGINT diff --git a/eng/helix/content/RunTests/TestRunner.cs b/eng/helix/content/RunTests/TestRunner.cs index 8f103ae940e6..ffa23ab4bff3 100644 --- a/eng/helix/content/RunTests/TestRunner.cs +++ b/eng/helix/content/RunTests/TestRunner.cs @@ -144,7 +144,7 @@ await ProcessUtil.RunAsync($"{Options.DotnetRoot}/dotnet", 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; } diff --git a/src/Components/Components/src/PlatformInfo.cs b/src/Components/Components/src/PlatformInfo.cs index e1de5ff13b7a..fe7c7ea4c685 100644 --- a/src/Components/Components/src/PlatformInfo.cs +++ b/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 @@ internal static class PlatformInfo static PlatformInfo() { - IsWebAssembly = RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); + IsWebAssembly = OperatingSystem.IsBrowser(); } } } diff --git a/src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorage.cs b/src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorage.cs index 4445265fffa8..42dd5b0cb35c 100644 --- a/src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorage.cs +++ b/src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorage.cs @@ -32,7 +32,7 @@ private readonly ConcurrentDictionary _cachedDataProtect 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."); } diff --git a/src/Components/WebAssembly/Server/src/TargetPickerUi.cs b/src/Components/WebAssembly/Server/src/TargetPickerUi.cs index 611eeac13c3b..100d9a48ebaf 100644 --- a/src/Components/WebAssembly/Server/src/TargetPickerUi.cs +++ b/src/Components/WebAssembly/Server/src/TargetPickerUi.cs @@ -162,17 +162,17 @@ private string GetLaunchChromeInstructions(string targetApplicationUrl) var profilePath = Path.Combine(Path.GetTempPath(), "blazor-chrome-debug"); var debuggerPort = new Uri(_browserHost).Port; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { return $@"

Press Win+R and enter the following:

chrome --remote-debugging-port={debuggerPort} --user-data-dir=""{profilePath}"" {targetApplicationUrl}

"; } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + else if (OperatingSystem.IsLinux()) { return $@"

In a terminal window execute the following:

google-chrome --remote-debugging-port={debuggerPort} --user-data-dir={profilePath} {targetApplicationUrl}

"; } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if (OperatingSystem.IsMacOS()) { return $@"

Execute the following:

open /Applications/Google\ Chrome.app --args --remote-debugging-port={debuggerPort} --user-data-dir={profilePath} {targetApplicationUrl}

"; @@ -188,12 +188,12 @@ private string GetLaunchEdgeInstructions(string targetApplicationUrl) var profilePath = Path.Combine(Path.GetTempPath(), "blazor-edge-debug"); var debuggerPort = new Uri(_browserHost).Port; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { return $@"

Press Win+R and enter the following:

msedge --remote-debugging-port={debuggerPort} --user-data-dir=""{profilePath}"" --no-first-run {targetApplicationUrl}

"; } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if (OperatingSystem.IsMacOS()) { return $@"

In a terminal window execute the following:

open /Applications/Microsoft\ Edge\ Dev.app --args --remote-debugging-port={debuggerPort} --user-data-dir={profilePath} {targetApplicationUrl}

"; diff --git a/src/Components/WebAssembly/WebAssembly/src/Rendering/RendererRegistry.cs b/src/Components/WebAssembly/WebAssembly/src/Rendering/RendererRegistry.cs index 2cadfb73693b..31a063992435 100644 --- a/src/Components/WebAssembly/WebAssembly/src/Rendering/RendererRegistry.cs +++ b/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 @@ internal static class RendererRegistry static RendererRegistry() { - bool _isWebAssembly = RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); - if (_isWebAssembly) + if (OperatingSystem.IsBrowser()) { _renderers = new Dictionary(); } diff --git a/src/Components/WebAssembly/WebAssembly/src/Services/LazyAssemblyLoader.cs b/src/Components/WebAssembly/WebAssembly/src/Services/LazyAssemblyLoader.cs index 13e2ded5722f..e5a2ec6098a0 100644 --- a/src/Components/WebAssembly/WebAssembly/src/Services/LazyAssemblyLoader.cs +++ b/src/Components/WebAssembly/WebAssembly/src/Services/LazyAssemblyLoader.cs @@ -6,7 +6,6 @@ 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 @@ public LazyAssemblyLoader(IJSRuntime jsRuntime) /// A list of the loaded public async Task> LoadAssembliesAsync(IEnumerable assembliesToLoad) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"))) + if (OperatingSystem.IsBrowser()) { return await LoadAssembliesInClientAsync(assembliesToLoad); } diff --git a/src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsFileProvider.cs b/src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsFileProvider.cs index 4e5771f7c33c..4cf84f3ed7d4 100644 --- a/src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsFileProvider.cs +++ b/src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsFileProvider.cs @@ -7,7 +7,6 @@ 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 // <>\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; diff --git a/src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsFileProviderTests.cs b/src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsFileProviderTests.cs index 1fae0b3daa58..a33f94ebaa94 100644 --- a/src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsFileProviderTests.cs +++ b/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 @@ public void GetDirectoryContents_PartialMatchFails(string requestedUrl) // Assert Assert.Empty(directory); } - + [Fact] public void GetDirectoryContents_HandlersEmptyPath() { @@ -164,7 +163,7 @@ public void StaticWebAssetsFileProviderWithEmptyBasePath_FindsFile() 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 @@ public void GetFileInfo_DoesNotMatch_IncompletePrefixSegments() 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 @@ public void GetFileInfo_Prefix_RespectsOsCaseSensitivity() 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)); diff --git a/src/Hosting/Server.IntegrationTesting/src/ApplicationPublisher.cs b/src/Hosting/Server.IntegrationTesting/src/ApplicationPublisher.cs index 5f64d971c283..df03c9487026 100644 --- a/src/Hosting/Server.IntegrationTesting/src/ApplicationPublisher.cs +++ b/src/Hosting/Server.IntegrationTesting/src/ApplicationPublisher.cs @@ -106,15 +106,15 @@ public virtual Task Publish(DeploymentParameters deploymen 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; } diff --git a/src/Hosting/Server.IntegrationTesting/src/Common/DotNetCommands.cs b/src/Hosting/Server.IntegrationTesting/src/Common/DotNetCommands.cs index e6d4924076f3..8c93ff3977cd 100644 --- a/src/Hosting/Server.IntegrationTesting/src/Common/DotNetCommands.cs +++ b/src/Hosting/Server.IntegrationTesting/src/Common/DotNetCommands.cs @@ -63,7 +63,7 @@ public static string GetDotNetInstallDir(RuntimeArchitecture arch) { 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 @@ public static string GetDotNetExecutable(RuntimeArchitecture arch) var dotnetFile = "dotnet"; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { dotnetFile += ".exe"; } diff --git a/src/Hosting/Server.IntegrationTesting/src/Deployers/NginxDeployer.cs b/src/Hosting/Server.IntegrationTesting/src/Deployers/NginxDeployer.cs index 90eff1c833df..0ba4df14c83f 100644 --- a/src/Hosting/Server.IntegrationTesting/src/Deployers/NginxDeployer.cs +++ b/src/Hosting/Server.IntegrationTesting/src/Deployers/NginxDeployer.cs @@ -8,7 +8,6 @@ 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 @@ public override async Task DeployAsync() 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 @@ private string GetUserName() return retVal; } - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { using (var process = new Process { diff --git a/src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs b/src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs index 6560f0f58e27..0bc6940736af 100644 --- a/src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs +++ b/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 @@ public override async Task DeployAsync() 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) { diff --git a/src/Hosting/Server.IntegrationTesting/src/TestMatrix.cs b/src/Hosting/Server.IntegrationTesting/src/TestMatrix.cs index ef8a47a5a698..de17dfc35b4a 100644 --- a/src/Hosting/Server.IntegrationTesting/src/TestMatrix.cs +++ b/src/Hosting/Server.IntegrationTesting/src/TestMatrix.cs @@ -156,13 +156,13 @@ private static string SkipIfServerIsNotSupportedOnThisOS(ServerType server) 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 @@ private bool CheckTfmIsSupportedForServer(string tfm, ServerType server) 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 @@ private string SkipIfArchitectureNotSupportedOnCurrentSystem(RuntimeArchitecture } // 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) diff --git a/src/Hosting/Server.IntegrationTesting/src/xunit/IISExpressAncmSchema.cs b/src/Hosting/Server.IntegrationTesting/src/xunit/IISExpressAncmSchema.cs index 53ea67ddd2a3..79d45951ef96 100644 --- a/src/Hosting/Server.IntegrationTesting/src/xunit/IISExpressAncmSchema.cs +++ b/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 @@ public class IISExpressAncmSchema 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 @@ static IISExpressAncmSchema() SkipReason = SupportsInProcessHosting ? null : "IIS Express must be upgraded to support in-process hosting."; } } -} \ No newline at end of file +} diff --git a/src/Http/Http/src/BindingAddress.cs b/src/Http/Http/src/BindingAddress.cs index 9ce9184c7153..b74d14040280 100644 --- a/src/Http/Http/src/BindingAddress.cs +++ b/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 @@ public string UnixPipePath 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 @@ public static BindingAddress Parse(string address) else { var unixPipeHostPrefixLength = UnixPipeHostPrefix.Length; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { // Windows has drive letters and volume separator (c:) unixPipeHostPrefixLength += 2; diff --git a/src/Identity/ApiAuthorization.IdentityServer/src/Configuration/ConfigureSigningCredentials.cs b/src/Identity/ApiAuthorization.IdentityServer/src/Configuration/ConfigureSigningCredentials.cs index 57248ed28407..472eb95b28ef 100644 --- a/src/Identity/ApiAuthorization.IdentityServer/src/Configuration/ConfigureSigningCredentials.cs +++ b/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 @@ public SigningCredentials LoadKey() 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) diff --git a/src/Identity/ApiAuthorization.IdentityServer/test/Configuration/ConfigureSigningCredentialsTests.cs b/src/Identity/ApiAuthorization.IdentityServer/test/Configuration/ConfigureSigningCredentialsTests.cs index b14fb61d15c2..542178125a7a 100644 --- a/src/Identity/ApiAuthorization.IdentityServer/test/Configuration/ConfigureSigningCredentialsTests.cs +++ b/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 @@ public class ConfigureSigningCredentialsTests // 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] diff --git a/src/Identity/ApiAuthorization.IdentityServer/test/Configuration/SigningKeysLoaderTests.cs b/src/Identity/ApiAuthorization.IdentityServer/test/Configuration/SigningKeysLoaderTests.cs index 96a3bf74b764..a2c03e92f686 100644 --- a/src/Identity/ApiAuthorization.IdentityServer/test/Configuration/SigningKeysLoaderTests.cs +++ b/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 @@ public class SigningKeysLoaderTests // 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] diff --git a/src/Middleware/Diagnostics/test/UnitTests/ExceptionDetailsProviderTest.cs b/src/Middleware/Diagnostics/test/UnitTests/ExceptionDetailsProviderTest.cs index 76351e6cba69..eb7a7409c489 100644 --- a/src/Middleware/Diagnostics/test/UnitTests/ExceptionDetailsProviderTest.cs +++ b/src/Middleware/Diagnostics/test/UnitTests/ExceptionDetailsProviderTest.cs @@ -6,8 +6,6 @@ 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 @@ public static TheoryData RelativePathsData "TestFiles/SourceFile.txt" }; - if (!(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))) + if (!(OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) { data.Add(@"TestFiles\SourceFile.txt"); } diff --git a/src/Middleware/SpaServices.Extensions/src/Npm/NodeScriptRunner.cs b/src/Middleware/SpaServices.Extensions/src/Npm/NodeScriptRunner.cs index 9631b29ef29c..4e9a438241f1 100644 --- a/src/Middleware/SpaServices.Extensions/src/Npm/NodeScriptRunner.cs +++ b/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 @@ public NodeScriptRunner(string workingDirectory, string scriptName, string argum 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 @@ public NodeScriptRunner(string workingDirectory, string scriptName, string argum StdErr = new EventedStreamReader(_npmProcess.StandardError); applicationStoppingToken.Register(((IDisposable)this).Dispose); - + if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.NodeServices.Npm.NpmStarted")) { diagnosticSource.Write( diff --git a/src/Middleware/SpaServices.Extensions/test/SpaServicesExtensionsTests.cs b/src/Middleware/SpaServices.Extensions/test/SpaServicesExtensionsTests.cs index d8d1c8a2ab63..b11e9a08e1e8 100644 --- a/src/Middleware/SpaServices.Extensions/test/SpaServicesExtensionsTests.cs +++ b/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 @@ public virtual void OnNpmStarted(ProcessStartInfo processStartInfo, Process proc } private string GetPlatformSpecificWaitCommand() - => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "waitWindows" : "wait"; + => OperatingSystem.IsWindows() ? "waitWindows" : "wait"; private IApplicationBuilder GetApplicationBuilder(IServiceProvider serviceProvider = null) { diff --git a/src/Middleware/WebSockets/test/ConformanceTests/Autobahn/Executable.cs b/src/Middleware/WebSockets/test/ConformanceTests/Autobahn/Executable.cs index cdd753bf3ec1..c20f55786bc0 100644 --- a/src/Middleware/WebSockets/test/ConformanceTests/Autobahn/Executable.cs +++ b/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; } diff --git a/src/Security/Authentication/Negotiate/samples/NegotiateAuthSample/Startup.cs b/src/Security/Authentication/Negotiate/samples/NegotiateAuthSample/Startup.cs index c2b0b0ba7f81..db6c90410363 100644 --- a/src/Security/Authentication/Negotiate/samples/NegotiateAuthSample/Startup.cs +++ b/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 @@ public void ConfigureServices(IServiceCollection services) services.AddAuthentication(NegotiateDefaults.AuthenticationScheme) .AddNegotiate(options => { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (OperatingSystem.IsLinux()) { /* options.EnableLdap("DOMAIN.net"); diff --git a/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateState.cs b/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateState.cs index 0b827e9dc35b..e5b21ca5cab0 100644 --- a/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateState.cs +++ b/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateState.cs @@ -6,7 +6,6 @@ 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 @@ static ReflectedNegotiateState() _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 @@ private byte[] GetOutgoingBlob(byte[] incomingBlob, out BlobErrorType status, ou // 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; diff --git a/src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs b/src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs index a1b5de84e323..6be56aff0812 100644 --- a/src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs +++ b/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 @@ public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder) } // 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(); services.AddTransient(); @@ -50,7 +50,8 @@ public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder) AuthenticationScheme = IISServerDefaults.AuthenticationScheme }); services.Configure( - options => { + options => + { options.ServerAddresses = iisConfigData.pwzBindings.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); options.ForwardWindowsAuthentication = iisConfigData.fWindowsAuthEnabled || iisConfigData.fBasicAuthEnabled; options.MaxRequestBodySize = iisConfigData.maxRequestBodySize; diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Infrastructure/RequiresIISAttribute.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Infrastructure/RequiresIISAttribute.cs index d6fc23a8035c..a0e4e909a156 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Infrastructure/RequiresIISAttribute.cs +++ b/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 @@ static RequiresIISAttribute() return; } - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { _skipReasonStatic = "IIS tests can only be run on Windows"; return; diff --git a/src/Servers/Kestrel/Core/src/Internal/Certificates/CertificateConfigLoader.cs b/src/Servers/Kestrel/Core/src/Internal/Certificates/CertificateConfigLoader.cs index 9e35d4097bf7..f23db490e44b 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Certificates/CertificateConfigLoader.cs +++ b/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 @@ public CertificateConfigLoader(IHostEnvironment hostEnvironment, ILogger 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; diff --git a/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs b/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs index 148476b459a5..fb4294748fec 100644 --- a/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs +++ b/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs @@ -48,17 +48,17 @@ public static class H2SpecCommands 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 @@ public static async Task RunTest(string testId, int port, bool https, ILogger lo 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") { diff --git a/src/Servers/Kestrel/test/Interop.FunctionalTests/SkipIfChromeUnavailableAttribute.cs b/src/Servers/Kestrel/test/Interop.FunctionalTests/SkipIfChromeUnavailableAttribute.cs index b7101b907623..8c9079fb5933 100644 --- a/src/Servers/Kestrel/test/Interop.FunctionalTests/SkipIfChromeUnavailableAttribute.cs +++ b/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 @@ public class SkipIfChromeUnavailableAttribute : Attribute, ITestCondition 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"); } diff --git a/src/Shared/CertificateGeneration/CertificateManager.cs b/src/Shared/CertificateGeneration/CertificateManager.cs index cc336e8af0d6..a44055c80f88 100644 --- a/src/Shared/CertificateGeneration/CertificateManager.cs +++ b/src/Shared/CertificateGeneration/CertificateManager.cs @@ -7,7 +7,6 @@ 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 @@ internal abstract class CertificateManager 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(); diff --git a/src/Shared/Process/ProcessExtensions.cs b/src/Shared/Process/ProcessExtensions.cs index 5fbefcdb241e..b38ec37d0883 100644 --- a/src/Shared/Process/ProcessExtensions.cs +++ b/src/Shared/Process/ProcessExtensions.cs @@ -6,13 +6,11 @@ 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 @@ internal static class ProcessExtensions public static void KillTree(this Process process, TimeSpan timeout) { var pid = process.Id; - if (_isWindows) + if (OperatingSystem.IsWindows()) { RunProcessAndWaitForExit( "taskkill", diff --git a/src/SignalR/clients/ts/FunctionalTests/Program.cs b/src/SignalR/clients/ts/FunctionalTests/Program.cs index 358bba527e38..cc3f89c69f78 100644 --- a/src/SignalR/clients/ts/FunctionalTests/Program.cs +++ b/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 @@ public static Task Main(string[] args) 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"); diff --git a/src/SignalR/server/StackExchangeRedis/test/Docker.cs b/src/SignalR/server/StackExchangeRedis/test/Docker.cs index cdcbe9bfccf9..fd201d14fede 100644 --- a/src/SignalR/server/StackExchangeRedis/test/Docker.cs +++ b/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";