From 24b90ba970f506af7a007c49ea43d13eea77d48e Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 29 Nov 2020 10:05:37 +0100 Subject: [PATCH 1/8] Changed Hosting --- .../src/StaticWebAssets/StaticWebAssetsFileProvider.cs | 3 +-- .../StaticWebAssets/StaticWebAssetsFileProviderTests.cs | 9 ++++----- .../src/ApplicationPublisher.cs | 6 +++--- .../src/Common/DotNetCommands.cs | 4 ++-- .../src/Deployers/NginxDeployer.cs | 5 ++--- .../src/Deployers/SelfHostDeployer.cs | 3 +-- src/Hosting/Server.IntegrationTesting/src/TestMatrix.cs | 8 ++++---- .../src/xunit/IISExpressAncmSchema.cs | 7 +++---- 8 files changed, 20 insertions(+), 25 deletions(-) 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 +} From ad8667da0bf7b3d096e4ceac23a5bca91fe6b039 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 29 Nov 2020 10:08:35 +0100 Subject: [PATCH 2/8] Changed Http --- src/Http/Http/src/BindingAddress.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Http/Http/src/BindingAddress.cs b/src/Http/Http/src/BindingAddress.cs index 94efb0c87972..7a3147653b4c 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 { @@ -35,7 +34,7 @@ public string UnixPipePath } 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--; @@ -98,7 +97,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; From c18ab8aeda19955feab069133ffc39c5414d5660 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 29 Nov 2020 10:12:20 +0100 Subject: [PATCH 3/8] Changed Identity --- .../src/Configuration/ConfigureSigningCredentials.cs | 5 ++--- .../test/Configuration/ConfigureSigningCredentialsTests.cs | 6 +++--- .../test/Configuration/SigningKeysLoaderTests.cs | 7 +++---- 3 files changed, 8 insertions(+), 10 deletions(-) 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] From eeb16584ecbbfd7e35720c23c1ea26738f5a8afc Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 29 Nov 2020 10:18:15 +0100 Subject: [PATCH 4/8] Changed Middleware --- .../test/UnitTests/ExceptionDetailsProviderTest.cs | 4 +--- .../SpaServices.Extensions/src/Npm/NodeScriptRunner.cs | 5 ++--- .../test/SpaServicesExtensionsTests.cs | 3 +-- .../WebSockets/test/ConformanceTests/Autobahn/Executable.cs | 3 +-- 4 files changed, 5 insertions(+), 10 deletions(-) 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; } From 0c0d034336d826dd0194e84e3e4e6d06f3d3257c Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 29 Nov 2020 10:23:55 +0100 Subject: [PATCH 5/8] Changed Security --- .../Negotiate/samples/NegotiateAuthSample/Startup.cs | 4 ++-- .../Negotiate/src/Internal/ReflectedNegotiateState.cs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) 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; From 9cf73ebf25e7b8c2db4dd410b13544c51f6fc921 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 29 Nov 2020 10:33:14 +0100 Subject: [PATCH 6/8] Changed Servers --- .../IIS/src/WebHostBuilderIISExtensions.cs | 11 ++--- .../Infrastructure/RequiresIISAttribute.cs | 3 +- .../Certificates/CertificateConfigLoader.cs | 3 +- .../Middleware/HttpsConnectionMiddleware.cs | 5 +-- .../Core/test/SniOptionsSelectorTests.cs | 3 +- .../src/Internal/LibuvConstants.cs | 42 +++++++++---------- .../src/Internal/ListenerPrimary.cs | 2 +- .../src/Internal/Networking/PlatformApis.cs | 5 +-- .../src/Internal/SocketConnection.cs | 8 ++-- .../Kestrel/shared/test/TestResources.cs | 3 +- .../Interop.FunctionalTests/H2SpecCommands.cs | 8 ++-- .../SkipIfChromeUnavailableAttribute.cs | 7 ++-- 12 files changed, 46 insertions(+), 54 deletions(-) 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 ee3a1edcc054..7097e49fc9f9 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 X509Certificate2 LoadCertificate(CertificateConfig certInfo, string endpo if (certificate != null) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { return PersistKey(certificate); } diff --git a/src/Servers/Kestrel/Core/src/Middleware/HttpsConnectionMiddleware.cs b/src/Servers/Kestrel/Core/src/Middleware/HttpsConnectionMiddleware.cs index 6626fd04a04f..b810c0a0dcdf 100644 --- a/src/Servers/Kestrel/Core/src/Middleware/HttpsConnectionMiddleware.cs +++ b/src/Servers/Kestrel/Core/src/Middleware/HttpsConnectionMiddleware.cs @@ -8,7 +8,6 @@ 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; @@ -456,7 +455,7 @@ internal static HttpProtocols ValidateAndNormalizeHttpProtocols(HttpProtocols ht // 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); } @@ -476,7 +475,7 @@ internal static HttpProtocols ValidateAndNormalizeHttpProtocols(HttpProtocols ht 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 diff --git a/src/Servers/Kestrel/Core/test/SniOptionsSelectorTests.cs b/src/Servers/Kestrel/Core/test/SniOptionsSelectorTests.cs index adbe314802be..bbe148069d99 100644 --- a/src/Servers/Kestrel/Core/test/SniOptionsSelectorTests.cs +++ b/src/Servers/Kestrel/Core/test/SniOptionsSelectorTests.cs @@ -6,7 +6,6 @@ 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 @@ public void CloneSslOptionsClonesAllProperties() CipherSuitesPolicy cipherSuitesPolicy = null; - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { try { diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConstants.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConstants.cs index 1e5b7bb75b61..d94e1fa8a39b 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConstants.cs +++ b/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 @@ public static bool IsConnectionReset(int errno) 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 @@ public static bool IsConnectionReset(int errno) 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 @@ public static bool IsConnectionReset(int errno) 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 @@ public static bool IsConnectionReset(int errno) 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 @@ public static bool IsConnectionReset(int errno) 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 @@ public static bool IsConnectionReset(int errno) 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 @@ public static bool IsConnectionReset(int errno) 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; } diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs index 6db3e4bffce8..9b7528935f5c 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs @@ -26,7 +26,7 @@ internal class ListenerPrimary : Listener 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 diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/PlatformApis.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/PlatformApis.cs index fd5003f0c79c..505acb2d230d 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/PlatformApis.cs +++ b/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) diff --git a/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs index f1b00d556b44..de8b975af1c0 100644 --- a/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs +++ b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs @@ -6,7 +6,6 @@ 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 @@ internal SocketConnection(Socket socket, // 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 @@ private static bool IsConnectionResetError(SocketError errorCode) { 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 @@ private static bool IsConnectionAbortError(SocketError errorCode) // 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()); } } } diff --git a/src/Servers/Kestrel/shared/test/TestResources.cs b/src/Servers/Kestrel/shared/test/TestResources.cs index 760eb8105132..ae26a1c5e98a 100644 --- a/src/Servers/Kestrel/shared/test/TestResources.cs +++ b/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 @@ public static class TestResources 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; 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"); } From 78f532ce4394516b1ed6d02d7520feebd579a6b5 Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 29 Nov 2020 10:38:12 +0100 Subject: [PATCH 7/8] Changed from RuntimeInterop to OperatingSystem --- eng/helix/content/RunTests/ProcessUtil.cs | 4 ++-- eng/helix/content/RunTests/TestRunner.cs | 2 +- src/Components/Components/src/PlatformInfo.cs | 4 ++-- .../ProtectedBrowserStorage/ProtectedBrowserStorage.cs | 2 +- .../WebAssembly/Server/src/TargetPickerUi.cs | 10 +++++----- .../WebAssembly/src/Rendering/RendererRegistry.cs | 4 +--- .../WebAssembly/src/Services/LazyAssemblyLoader.cs | 3 +-- src/Shared/CertificateGeneration/CertificateManager.cs | 5 ++--- src/Shared/CommandLineUtils/Utilities/DotNetMuxer.cs | 3 +-- src/Shared/Process/ProcessExtensions.cs | 4 +--- src/SignalR/clients/ts/FunctionalTests/Program.cs | 3 +-- src/SignalR/server/StackExchangeRedis/test/Docker.cs | 2 +- 12 files changed, 19 insertions(+), 27 deletions(-) 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/Shared/CertificateGeneration/CertificateManager.cs b/src/Shared/CertificateGeneration/CertificateManager.cs index d767db8b8f81..44871bd3f96b 100644 --- a/src/Shared/CertificateGeneration/CertificateManager.cs +++ b/src/Shared/CertificateGeneration/CertificateManager.cs @@ -6,7 +6,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; @@ -27,11 +26,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/CommandLineUtils/Utilities/DotNetMuxer.cs b/src/Shared/CommandLineUtils/Utilities/DotNetMuxer.cs index ac6a0985ef3d..e60a1e43a7e7 100644 --- a/src/Shared/CommandLineUtils/Utilities/DotNetMuxer.cs +++ b/src/Shared/CommandLineUtils/Utilities/DotNetMuxer.cs @@ -9,7 +9,6 @@ using System; using System.Diagnostics; using System.IO; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.CommandLineUtils { @@ -41,7 +40,7 @@ public static string MuxerPathOrDefault() private static string? TryFindMuxerPath() { var fileName = MuxerName; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { fileName += ".exe"; } 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"; From 887671ab5d9d9a3e922937781d0c8879c833d5af Mon Sep 17 00:00:00 2001 From: Stefan Nikolei Date: Sun, 29 Nov 2020 11:01:57 +0100 Subject: [PATCH 8/8] Revert changes in DotNetMuxer --- src/Shared/CommandLineUtils/Utilities/DotNetMuxer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Shared/CommandLineUtils/Utilities/DotNetMuxer.cs b/src/Shared/CommandLineUtils/Utilities/DotNetMuxer.cs index e60a1e43a7e7..ac6a0985ef3d 100644 --- a/src/Shared/CommandLineUtils/Utilities/DotNetMuxer.cs +++ b/src/Shared/CommandLineUtils/Utilities/DotNetMuxer.cs @@ -9,6 +9,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.CommandLineUtils { @@ -40,7 +41,7 @@ public static string MuxerPathOrDefault() private static string? TryFindMuxerPath() { var fileName = MuxerName; - if (OperatingSystem.IsWindows()) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { fileName += ".exe"; }