Skip to content

Commit 0a69eda

Browse files
Copilotnkolev92
andcommitted
Use RuntimeInformation.IsOSPlatform for all frameworks, remove conditional compilation
Co-authored-by: nkolev92 <[email protected]>
1 parent f419bfc commit 0a69eda

1 file changed

Lines changed: 2 additions & 48 deletions

File tree

src/NuGet.Core/NuGet.Common/RuntimeEnvironmentHelper.cs

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public static class RuntimeEnvironmentHelper
3434
process => process.Equals(currentProcessName, StringComparison.OrdinalIgnoreCase));
3535
});
3636

37-
[DllImport("libc")]
38-
static extern int uname(IntPtr buf);
39-
4037
public static bool IsWindows
4138
{
4239
get => _isWindows.Value;
@@ -95,51 +92,8 @@ public static bool IsMacOSX
9592

9693
private static bool GetIsMacOSX()
9794
{
98-
#if IS_CORECLR
99-
// This API does work on full framework but it requires a newer nuget client (RID aware)
100-
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX))
101-
{
102-
return true;
103-
}
104-
105-
return false;
106-
#else
107-
// On Windows, return false immediately to avoid first-chance exception from uname() P/Invoke
108-
if (IsWindows)
109-
{
110-
return false;
111-
}
112-
113-
var buf = IntPtr.Zero;
114-
115-
try
116-
{
117-
buf = Marshal.AllocHGlobal(8192);
118-
119-
// This is a hacktastic way of getting sysname from uname ()
120-
if (uname(buf) == 0)
121-
{
122-
var os = Marshal.PtrToStringAnsi(buf);
123-
124-
if (os == "Darwin")
125-
{
126-
return true;
127-
}
128-
}
129-
}
130-
catch
131-
{
132-
}
133-
finally
134-
{
135-
if (buf != IntPtr.Zero)
136-
{
137-
Marshal.FreeHGlobal(buf);
138-
}
139-
}
140-
141-
return false;
142-
#endif
95+
// RuntimeInformation.IsOSPlatform is available on .NET Framework 4.7.1+ and .NET Core
96+
return System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX);
14397
}
14498

14599
public static bool IsLinux

0 commit comments

Comments
 (0)