Skip to content

Commit ac3677c

Browse files
committed
Remove references to PlatformAbstractions.
This will allow us to remove the PlatformAbstractions library from dotnet/runtime. Contributes to dotnet/runtime#3470
1 parent 0d61183 commit ac3677c

File tree

93 files changed

+593
-423
lines changed

Some content is hidden

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

93 files changed

+593
-423
lines changed

eng/Version.Details.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
<Uri>https://github.com/dotnet/runtime</Uri>
1414
<Sha>c74407fcaff466a17b6e98f1dcc969248de506fe</Sha>
1515
</Dependency>
16-
<Dependency Name="Microsoft.DotNet.PlatformAbstractions" Version="5.0.0-preview.3.20180.15">
17-
<Uri>https://github.com/dotnet/runtime</Uri>
18-
<Sha>c74407fcaff466a17b6e98f1dcc969248de506fe</Sha>
16+
<Dependency Name="Microsoft.DotNet.XUnitExtensions" Version="5.0.0-beta.20171.1">
17+
<Uri>https://github.com/dotnet/arcade</Uri>
18+
<Sha>7dbc907fa03eacf4c57f827cb4235d77b7ed4fcd</Sha>
1919
</Dependency>
2020
<Dependency Name="Microsoft.NET.HostModel" Version="5.0.0-preview.3.20180.15">
2121
<Uri>https://github.com/dotnet/runtime</Uri>

eng/Versions.props

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<MicrosoftExtensionsDependencyModelVersion>2.1.0-preview2-26306-03</MicrosoftExtensionsDependencyModelVersion>
1919
<MicrosoftApplicationInsightsPackageVersion>2.0.0</MicrosoftApplicationInsightsPackageVersion>
2020
<NETStandardLibraryNETFrameworkVersion>2.0.1-servicing-26011-01</NETStandardLibraryNETFrameworkVersion>
21-
<PlatformAbstractionsVersion>2.0.0</PlatformAbstractionsVersion>
2221
<NewtonsoftJsonPackageVersion>11.0.1</NewtonsoftJsonPackageVersion>
2322
<NewtonsoftJsonVersion>$(NewtonsoftJsonPackageVersion)</NewtonsoftJsonVersion>
2423
<SystemDiagnosticsFileVersionInfoVersion>4.0.0</SystemDiagnosticsFileVersionInfoVersion>
@@ -30,11 +29,9 @@
3029
<MicrosoftNETCoreAppRefPackageVersion>5.0.0-preview.3.20180.15</MicrosoftNETCoreAppRefPackageVersion>
3130
<MicrosoftNETCoreAppRuntimewinx64PackageVersion>5.0.0-preview.3.20180.15</MicrosoftNETCoreAppRuntimewinx64PackageVersion>
3231
<MicrosoftNETCoreAppRuntimePackageVersion>$(MicrosoftNETCoreAppRuntimewinx64PackageVersion)</MicrosoftNETCoreAppRuntimePackageVersion>
33-
<MicrosoftDotNetPlatformAbstractionsPackageVersion>5.0.0-preview.3.20180.15</MicrosoftDotNetPlatformAbstractionsPackageVersion>
3432
<MicrosoftExtensionsDependencyModelPackageVersion>5.0.0-preview.3-runtime.20180.15</MicrosoftExtensionsDependencyModelPackageVersion>
3533
<MicrosoftNETCoreDotNetHostResolverPackageVersion>5.0.0-preview.3.20180.15</MicrosoftNETCoreDotNetHostResolverPackageVersion>
3634
<MicrosoftNETHostModelVersion>5.0.0-preview.3.20180.15</MicrosoftNETHostModelVersion>
37-
<PlatformAbstractionsVersion>$(MicrosoftDotNetPlatformAbstractionsPackageVersion)</PlatformAbstractionsVersion>
3835
<MicrosoftExtensionsDependencyModelVersion>$(MicrosoftExtensionsDependencyModelPackageVersion)</MicrosoftExtensionsDependencyModelVersion>
3936
</PropertyGroup>
4037
<PropertyGroup>
@@ -133,6 +130,7 @@
133130
<PropertyGroup>
134131
<FluentAssertionsVersion>4.19.2</FluentAssertionsVersion>
135132
<FluentAssertionsJsonVersion>4.19.0</FluentAssertionsJsonVersion>
133+
<MicrosoftDotNetXUnitExtensionsVersion>5.0.0-beta.20171.1</MicrosoftDotNetXUnitExtensionsVersion>
136134
</PropertyGroup>
137135
<PropertyGroup>
138136
<ExeExtension>.exe</ExeExtension>

src/Cli/Microsoft.DotNet.Cli.Utils/Constants.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using Microsoft.DotNet.PlatformAbstractions;
4+
using System.Runtime.InteropServices;
55

66
namespace Microsoft.DotNet.Cli.Utils
77
{
88
public static class Constants
99
{
10-
private static Platform CurrentPlatform => RuntimeEnvironment.OperatingSystemPlatform;
1110
public const string DefaultConfiguration = "Debug";
1211

1312
public static readonly string ProjectFileName = "project.json";
1413
public static readonly string DotConfigDirectoryName = ".config";
15-
public static readonly string ExeSuffix = CurrentPlatform == Platform.Windows ? ".exe" : string.Empty;
14+
public static readonly string ExeSuffix =
15+
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty;
1616

1717
public static readonly string BinDirectoryName = "bin";
1818
public static readonly string ObjDirectoryName = "obj";

src/Cli/Microsoft.DotNet.Cli.Utils/DangerousFileDetector.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
using System;
55
using System.IO;
66
using System.Runtime.InteropServices;
7-
using Microsoft.DotNet.PlatformAbstractions;
8-
using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;
97

108
namespace Microsoft.DotNet.Cli.Utils
119
{
1210
internal class DangerousFileDetector : IDangerousFileDetector
1311
{
1412
public bool IsDangerous(string filePath)
1513
{
16-
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
14+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
1715
{
1816
return false;
1917
}

src/Cli/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.IO;
66
using System.Reflection;
77
using Microsoft.DotNet.Cli.Utils;
8-
using Microsoft.DotNet.PlatformAbstractions;
98

109
namespace Microsoft.DotNet.Cli
1110
{

src/Cli/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8-
using Microsoft.DotNet.PlatformAbstractions;
8+
using System.Runtime.InteropServices;
99

1010
namespace Microsoft.DotNet.Cli.Utils
1111
{
@@ -24,7 +24,7 @@ public IEnumerable<string> ExecutableExtensions
2424
if (_executableExtensions == null)
2525
{
2626

27-
_executableExtensions = RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows
27+
_executableExtensions = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
2828
? Environment.GetEnvironmentVariable("PATHEXT")
2929
.Split(';')
3030
.Select(e => e.ToLower().Trim('"'))
@@ -41,7 +41,7 @@ private IEnumerable<string> SearchPaths
4141
{
4242
if (_searchPaths == null)
4343
{
44-
var searchPaths = new List<string> { ApplicationEnvironment.ApplicationBasePath };
44+
var searchPaths = new List<string> { AppContext.BaseDirectory };
4545

4646
searchPaths.AddRange(Environment
4747
.GetEnvironmentVariable("PATH")

src/Cli/Microsoft.DotNet.Cli.Utils/FileNameSuffixes.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5-
using Microsoft.DotNet.PlatformAbstractions;
5+
using System.Runtime.InteropServices;
66

77
namespace Microsoft.DotNet.Cli.Utils
88
{
@@ -16,18 +16,25 @@ public static PlatformFileNameSuffixes CurrentPlatform
1616
{
1717
get
1818
{
19-
switch (RuntimeEnvironment.OperatingSystemPlatform)
19+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
2020
{
21-
case Platform.Windows:
22-
return Windows;
23-
case Platform.Darwin:
24-
return OSX;
25-
case Platform.Linux:
26-
return Linux;
27-
case Platform.FreeBSD:
28-
return FreeBSD;
29-
default:
30-
throw new InvalidOperationException("Unknown Platform");
21+
return Windows;
22+
}
23+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
24+
{
25+
return OSX;
26+
}
27+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
28+
{
29+
return Linux;
30+
}
31+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")))
32+
{
33+
return FreeBSD;
34+
}
35+
else
36+
{
37+
throw new InvalidOperationException("Unknown Platform");
3138
}
3239
}
3340
}

src/Cli/Microsoft.DotNet.Cli.Utils/FrameworkDependencyFile.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8-
using Microsoft.DotNet.PlatformAbstractions;
9-
8+
using System.Runtime.InteropServices;
109
using Microsoft.Extensions.DependencyModel;
1110

1211
namespace Microsoft.DotNet.Cli.Utils
@@ -28,11 +27,6 @@ public FrameworkDependencyFile()
2827
_dependencyContext = new Lazy<DependencyContext>(CreateDependencyContext);
2928
}
3029

31-
public bool SupportsCurrentRuntime()
32-
{
33-
return IsRuntimeSupported(RuntimeEnvironment.GetRuntimeIdentifier());
34-
}
35-
3630
public bool IsRuntimeSupported(string runtimeIdentifier)
3731
{
3832
return DependencyContext.RuntimeGraph.Any(g => g.Runtime == runtimeIdentifier);
@@ -46,18 +40,20 @@ public string GetNetStandardLibraryVersion()
4640
?.Version;
4741
}
4842

43+
#if NETCOREAPP
4944
public bool TryGetMostFitRuntimeIdentifier(
5045
string alternativeCurrentRuntimeIdentifier,
5146
string[] candidateRuntimeIdentifiers,
5247
out string mostFitRuntimeIdentifier)
5348
{
5449
return TryGetMostFitRuntimeIdentifier(
55-
RuntimeEnvironment.GetRuntimeIdentifier(),
50+
RuntimeInformation.RuntimeIdentifier,
5651
alternativeCurrentRuntimeIdentifier,
5752
DependencyContext.RuntimeGraph,
5853
candidateRuntimeIdentifiers,
5954
out mostFitRuntimeIdentifier);
6055
}
56+
#endif
6157

6258
internal static bool TryGetMostFitRuntimeIdentifier(
6359
string currentRuntimeIdentifier,

src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<SignAssembly>true</SignAssembly>
88
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
99
<IsPackable>true</IsPackable>
10+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1011
</PropertyGroup>
1112

1213
<ItemGroup>
@@ -15,7 +16,6 @@
1516

1617
<ItemGroup>
1718
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelPackageVersion)" />
18-
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(MicrosoftDotNetPlatformAbstractionsPackageVersion)" />
1919
<PackageReference Include="NuGet.Versioning" Version="$(NuGetVersioningPackageVersion)" />
2020
<PackageReference Include="NuGet.Packaging" Version="$(NuGetPackagingPackageVersion)" />
2121
<!-- nuget moved all type from NuGet.Packaging.Core to NuGet.Packaging and added type forwarding in 5.0.0-rtm.5821.

src/Cli/Microsoft.DotNet.Cli.Utils/PathUtility.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8+
using System.Runtime.InteropServices;
89
using Microsoft.DotNet.Cli.Utils;
9-
using Microsoft.DotNet.PlatformAbstractions;
1010

1111
namespace Microsoft.DotNet.Tools.Common
1212
{
@@ -152,7 +152,7 @@ public static string GetRelativePath(string path1, string path2, char separator,
152152
}
153153

154154
StringComparison compare;
155-
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
155+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
156156
{
157157
compare = StringComparison.OrdinalIgnoreCase;
158158
// check if paths are on the same volume
@@ -288,7 +288,7 @@ public static string RemoveExtraPathSeparators(string path)
288288
result = component;
289289

290290
// On Windows, manually append a separator for drive references because Path.Combine won't do so
291-
if (result.EndsWith(":") && RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
291+
if (result.EndsWith(":") && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
292292
{
293293
result += Path.DirectorySeparatorChar;
294294
}
@@ -311,7 +311,7 @@ public static bool HasExtension(this string filePath, string extension)
311311
{
312312
var comparison = StringComparison.Ordinal;
313313

314-
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
314+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
315315
{
316316
comparison = StringComparison.OrdinalIgnoreCase;
317317
}

0 commit comments

Comments
 (0)