diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs index de6294fee4..bbe6442f87 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.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 Microsoft.Extensions.PlatformAbstractions; +using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { @@ -28,32 +28,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure private static int? GetECONNRESET() { - switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - case Platform.Windows: - return -4077; - case Platform.Linux: - return -104; - case Platform.Darwin: - return -54; - default: - return null; + return -4077; } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -104; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return -54; + } + return null; } private static int? GetEADDRINUSE() { - switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - case Platform.Windows: - return -4091; - case Platform.Linux: - return -98; - case Platform.Darwin: - return -48; - default: - return null; + return -4091; } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -98; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return -48; + } + return null; } } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs index f485665bf9..17985da608 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs @@ -3,7 +3,6 @@ using System; using System.Runtime.InteropServices; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Networking { @@ -11,19 +10,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking { static PlatformApis() { -#if NETSTANDARD1_3 IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); -#else - var p = (int)Environment.OSVersion.Platform; - IsWindows = (p != 4) && (p != 6) && (p != 128); - - if (!IsWindows) - { - // When running on Mono in Darwin OSVersion doesn't return Darwin. It returns Unix instead. - IsDarwin = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Darwin; - } -#endif } public static bool IsWindows { get; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/project.json b/src/Microsoft.AspNetCore.Server.Kestrel/project.json index 4d875358f5..f6aeb0f17b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/project.json +++ b/src/Microsoft.AspNetCore.Server.Kestrel/project.json @@ -14,11 +14,11 @@ "dependencies": { "System.Buffers": "4.0.0-*", "System.Numerics.Vectors": "4.1.1-*", + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0-*", "System.Threading.Tasks.Extensions": "4.0.0-*", "Libuv": "1.9.0-*", "Microsoft.AspNetCore.Hosting": "1.0.0-*", - "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*" + "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*" }, "frameworks": { "net451": {