Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
<SystemMemoryVersion>4.5.5</SystemMemoryVersion>
<SystemNumericsVectorsVersion>4.5.0</SystemNumericsVectorsVersion>
<SystemReflectionMetadataVersion>6.0.1</SystemReflectionMetadataVersion>
<SystemRuntimeInteropServicesRuntimeInformationVersion>4.3.0</SystemRuntimeInteropServicesRuntimeInformationVersion>
<SystemSecurityAccessControlVersion>6.0.0</SystemSecurityAccessControlVersion>
<SystemSecurityCryptographyAlgorithmsVersion>4.3.1</SystemSecurityCryptographyAlgorithmsVersion>
<SystemSecurityCryptographyCngVersion>5.0.0</SystemSecurityCryptographyCngVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
#if !NETFRAMEWORK
using System.Runtime.InteropServices;
#endif

namespace Microsoft.Extensions.DependencyModel
{
Expand All @@ -14,6 +16,11 @@ internal sealed class EnvironmentWrapper : IEnvironment

public object? GetAppContextData(string name) => AppDomain.CurrentDomain.GetData(name);

public bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
public bool IsWindows() =>
#if NETFRAMEWORK
Environment.OSVersion.Platform == PlatformID.Win32NT;
#else
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ By default, the dependency manifest contains information about the application's

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Reference Include="System.Runtime" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="$(SystemRuntimeInteropServicesRuntimeInformationVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if !NETFRAMEWORK
using System.Runtime.InteropServices;
#endif

namespace Microsoft.Extensions.DependencyModel.Resolution
{
Expand All @@ -27,12 +29,21 @@ public class DotNetReferenceAssembliesPathResolver

private static string? GetDefaultDotNetReferenceAssembliesPath(IFileSystem fileSystem)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (
#if NETFRAMEWORK
System.Environment.OSVersion.Platform == System.PlatformID.Win32NT
#else
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
#endif
)
{
return null;
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
if (
#if !NETFRAMEWORK
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
#endif
fileSystem.Directory.Exists("/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks"))
{
return "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ public static class WindowsServiceHelpers
[SupportedOSPlatformGuard("windows")]
public static bool IsWindowsService()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (
#if NETFRAMEWORK
Environment.OSVersion.Platform != PlatformID.Win32NT
#else
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
#endif
)
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@ public static IServiceCollection AddWindowsService(this IServiceCollection servi

private static void AddWindowsServiceLifetime(IServiceCollection services, Action<WindowsServiceLifetimeOptions> configure)
{
#if !NETFRAMEWORK
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't seem all that valuable. According to 04442bf#r759693314 it's to workaround an issue in the analyzer. I wonder if that issue still exists?

Copy link
Contributor

@buyaa-n buyaa-n May 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if that issue still exists?

Probably would still warn as I don't see any annotation or guard. Isn't it windows only? Then we might want to add [SupportedOSPlatformGuard("windows")] attribute to this type to suppress the warnings here and propagate the warning to the callers

#endif

services.AddLogging(logging =>
{
#if !NETFRAMEWORK
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
#endif
logging.AddEventLog();
});
services.AddSingleton<IHostLifetime, WindowsServiceLifetime>();
Expand All @@ -129,7 +133,9 @@ public EventLogSettingsSetup(IHostEnvironment environment)

public void Configure(EventLogSettings settings)
{
#if !NETFRAMEWORK
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
#endif

if (string.IsNullOrEmpty(settings.SourceName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ internal static void SetDefaultContentRoot(IConfigurationBuilder hostConfigBuild
// any trailing directory separator characters. I'm not even sure the casing can ever be different from these APIs, but I think it makes sense to
// ignore case for Windows path comparisons given the file system is usually (always?) going to be case insensitive for the system path.
string cwd = Environment.CurrentDirectory;
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !string.Equals(cwd, Environment.SystemDirectory, StringComparison.OrdinalIgnoreCase))
if (
#if NETFRAMEWORK
Environment.OSVersion.Platform != PlatformID.Win32NT ||
#else
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ||
#endif
!string.Equals(cwd, Environment.SystemDirectory, StringComparison.OrdinalIgnoreCase))
{
hostConfigBuilder.AddInMemoryCollection(new[]
{
Expand Down Expand Up @@ -270,6 +276,8 @@ internal static void AddDefaultServices(HostBuilderContext hostingContext, IServ
bool isWindows =
#if NETCOREAPP
OperatingSystem.IsWindows();
#elif NETFRAMEWORK
Environment.OSVersion.Platform == PlatformID.Win32NT;
#else
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="$(SystemRuntimeInteropServicesRuntimeInformationVersion)" />
<Reference Include="System.Runtime" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ public ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions> options, IEnu
[UnsupportedOSPlatformGuard("windows")]
private static bool DoesConsoleSupportAnsi()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (
#if NETFRAMEWORK
Environment.OSVersion.Platform != PlatformID.Win32NT
#else
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
#endif
)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="$(SystemRuntimeInteropServicesRuntimeInformationVersion)" />
<PackageReference Include="System.ValueTuple" Version="$(SystemValueTupleVersion)" />
<Reference Include="System.Runtime" />
</ItemGroup>

Expand Down