Skip to content

Commit 7ce071b

Browse files
Switching from RuntimeInformation.IsOSPlatform(XYZ) to OperatingSystem.IsXYZ() (#28233)
* Changed Hosting * Changed Http * Changed Identity * Changed Middleware * Changed Security * Changed Servers * Changed from RuntimeInterop to OperatingSystem * Revert changes in DotNetMuxer Co-authored-by: Pranav K <[email protected]>
1 parent 5c897ac commit 7ce071b

File tree

41 files changed

+103
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+103
-132
lines changed

eng/helix/content/RunTests/ProcessUtil.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static Task CaptureDumpAsync(int pid)
5353
public static Task CaptureDumpAsync(int pid, string dumpFilePath)
5454
{
5555
// Skip this on OSX, we know it's unsupported right now
56-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
56+
if (OperatingSystem.IsMacOS())
5757
{
5858
// Can we capture stacks or do a gcdump instead?
5959
return Task.CompletedTask;
@@ -178,7 +178,7 @@ public static async Task<ProcessResult> RunAsync(
178178
await CaptureDumpAsync(process.Id, dumpFilePath);
179179
}
180180

181-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
181+
if (!OperatingSystem.IsWindows())
182182
{
183183
sys_kill(process.Id, sig: 2); // SIGINT
184184

eng/helix/content/RunTests/TestRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ await ProcessUtil.RunAsync($"{Options.DotnetRoot}/dotnet",
144144
cancellationToken: new CancellationTokenSource(TimeSpan.FromMinutes(2)).Token);
145145

146146
// ';' is the path separator on Windows, and ':' on Unix
147-
Options.Path += RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ";" : ":";
147+
Options.Path += OperatingSystem.IsWindows() ? ";" : ":";
148148
Options.Path += $"{Environment.GetEnvironmentVariable("DOTNET_CLI_HOME")}/.dotnet/tools";
149149
EnvironmentVariables["PATH"] = Options.Path;
150150
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System.Runtime.InteropServices;
4+
using System;
55

66
namespace Microsoft.AspNetCore.Components
77
{
@@ -11,7 +11,7 @@ internal static class PlatformInfo
1111

1212
static PlatformInfo()
1313
{
14-
IsWebAssembly = RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"));
14+
IsWebAssembly = OperatingSystem.IsBrowser();
1515
}
1616
}
1717
}

src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private readonly ConcurrentDictionary<string, IDataProtector> _cachedDataProtect
3232
private protected ProtectedBrowserStorage(string storeName, IJSRuntime jsRuntime, IDataProtectionProvider dataProtectionProvider)
3333
{
3434
// Performing data protection on the client would give users a false sense of security, so we'll prevent this.
35-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
35+
if (OperatingSystem.IsBrowser())
3636
{
3737
throw new PlatformNotSupportedException($"{GetType()} cannot be used when running in a browser.");
3838
}

src/Components/WebAssembly/Server/src/TargetPickerUi.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,17 @@ private string GetLaunchChromeInstructions(string targetApplicationUrl)
162162
var profilePath = Path.Combine(Path.GetTempPath(), "blazor-chrome-debug");
163163
var debuggerPort = new Uri(_browserHost).Port;
164164

165-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
165+
if (OperatingSystem.IsWindows())
166166
{
167167
return $@"<p>Press Win+R and enter the following:</p>
168168
<p><strong><code>chrome --remote-debugging-port={debuggerPort} --user-data-dir=""{profilePath}"" {targetApplicationUrl}</code></strong></p>";
169169
}
170-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
170+
else if (OperatingSystem.IsLinux())
171171
{
172172
return $@"<p>In a terminal window execute the following:</p>
173173
<p><strong><code>google-chrome --remote-debugging-port={debuggerPort} --user-data-dir={profilePath} {targetApplicationUrl}</code></strong></p>";
174174
}
175-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
175+
else if (OperatingSystem.IsMacOS())
176176
{
177177
return $@"<p>Execute the following:</p>
178178
<p><strong><code>open /Applications/Google\ Chrome.app --args --remote-debugging-port={debuggerPort} --user-data-dir={profilePath} {targetApplicationUrl}</code></strong></p>";
@@ -188,12 +188,12 @@ private string GetLaunchEdgeInstructions(string targetApplicationUrl)
188188
var profilePath = Path.Combine(Path.GetTempPath(), "blazor-edge-debug");
189189
var debuggerPort = new Uri(_browserHost).Port;
190190

191-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
191+
if (OperatingSystem.IsWindows())
192192
{
193193
return $@"<p>Press Win+R and enter the following:</p>
194194
<p><strong><code>msedge --remote-debugging-port={debuggerPort} --user-data-dir=""{profilePath}"" --no-first-run {targetApplicationUrl}</code></strong></p>";
195195
}
196-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
196+
else if (OperatingSystem.IsMacOS())
197197
{
198198
return $@"<p>In a terminal window execute the following:</p>
199199
<p><strong><code>open /Applications/Microsoft\ Edge\ Dev.app --args --remote-debugging-port={debuggerPort} --user-data-dir={profilePath} {targetApplicationUrl}</code></strong></p>";

src/Components/WebAssembly/WebAssembly/src/Rendering/RendererRegistry.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Runtime.InteropServices;
76

87
namespace Microsoft.AspNetCore.Components.WebAssembly.Rendering
98
{
@@ -19,8 +18,7 @@ internal static class RendererRegistry
1918

2019
static RendererRegistry()
2120
{
22-
bool _isWebAssembly = RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"));
23-
if (_isWebAssembly)
21+
if (OperatingSystem.IsBrowser())
2422
{
2523
_renderers = new Dictionary<int, WebAssemblyRenderer>();
2624
}

src/Components/WebAssembly/WebAssembly/src/Services/LazyAssemblyLoader.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.IO;
77
using System.Linq;
88
using System.Reflection;
9-
using System.Runtime.InteropServices;
109
using System.Runtime.Loader;
1110
using System.Threading.Tasks;
1211
using Microsoft.JSInterop;
@@ -48,7 +47,7 @@ public LazyAssemblyLoader(IJSRuntime jsRuntime)
4847
/// <returns>A list of the loaded <see cref="Assembly"/></returns>
4948
public async Task<IEnumerable<Assembly>> LoadAssembliesAsync(IEnumerable<string> assembliesToLoad)
5049
{
51-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
50+
if (OperatingSystem.IsBrowser())
5251
{
5352
return await LoadAssembliesInClientAsync(assembliesToLoad);
5453
}

src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsFileProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Diagnostics;
88
using System.IO;
99
using System.Linq;
10-
using System.Runtime.InteropServices;
1110
using Microsoft.AspNetCore.Http;
1211
using Microsoft.Extensions.FileProviders;
1312
using Microsoft.Extensions.Primitives;
@@ -28,7 +27,7 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
2827
// <<mylibrarypath>>\wwwroot\** to _content/mylibrary/**
2928
internal class StaticWebAssetsFileProvider : IFileProvider
3029
{
31-
private static readonly StringComparison FilePathComparison = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
30+
private static readonly StringComparison FilePathComparison = OperatingSystem.IsWindows() ?
3231
StringComparison.OrdinalIgnoreCase :
3332
StringComparison.Ordinal;
3433

src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsFileProviderTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.IO;
6-
using System.Runtime.InteropServices;
76
using Xunit;
87

98
namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
@@ -87,7 +86,7 @@ public void GetDirectoryContents_PartialMatchFails(string requestedUrl)
8786
// Assert
8887
Assert.Empty(directory);
8988
}
90-
89+
9190
[Fact]
9291
public void GetDirectoryContents_HandlersEmptyPath()
9392
{
@@ -164,7 +163,7 @@ public void StaticWebAssetsFileProviderWithEmptyBasePath_FindsFile()
164163
public void GetFileInfo_DoesNotMatch_IncompletePrefixSegments()
165164
{
166165
// Arrange
167-
var expectedResult = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
166+
var expectedResult = OperatingSystem.IsWindows();
168167
var provider = new StaticWebAssetsFileProvider(
169168
"_cont",
170169
Path.GetDirectoryName(typeof(StaticWebAssetsFileProviderTests).Assembly.Location));
@@ -180,7 +179,7 @@ public void GetFileInfo_DoesNotMatch_IncompletePrefixSegments()
180179
public void GetFileInfo_Prefix_RespectsOsCaseSensitivity()
181180
{
182181
// Arrange
183-
var expectedResult = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
182+
var expectedResult = OperatingSystem.IsWindows();
184183
var provider = new StaticWebAssetsFileProvider(
185184
"_content",
186185
Path.GetDirectoryName(typeof(StaticWebAssetsFileProviderTests).Assembly.Location));
@@ -196,7 +195,7 @@ public void GetFileInfo_Prefix_RespectsOsCaseSensitivity()
196195
public void GetDirectoryContents_Prefix_RespectsOsCaseSensitivity()
197196
{
198197
// Arrange
199-
var expectedResult = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
198+
var expectedResult = OperatingSystem.IsWindows();
200199
var provider = new StaticWebAssetsFileProvider(
201200
"_content",
202201
Path.GetDirectoryName(typeof(StaticWebAssetsFileProviderTests).Assembly.Location));

src/Hosting/Server.IntegrationTesting/src/ApplicationPublisher.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ public virtual Task<PublishedApplication> Publish(DeploymentParameters deploymen
106106
private static string GetRuntimeIdentifier(DeploymentParameters deploymentParameters)
107107
{
108108
var architecture = deploymentParameters.RuntimeArchitecture;
109-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
109+
if (OperatingSystem.IsWindows())
110110
{
111111
return "win-" + architecture;
112112
}
113-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
113+
if (OperatingSystem.IsLinux())
114114
{
115115
return "linux-" + architecture;
116116
}
117-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
117+
if (OperatingSystem.IsMacOS())
118118
{
119119
return "osx-" + architecture;
120120
}

0 commit comments

Comments
 (0)