From 1e753f7781ff9bea8769d6a3d241d9b2dc71bf8e Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 28 Apr 2016 16:30:32 -0700 Subject: [PATCH] Replaces references to Microsoft.Extensions.PlatformAbstractions with Microsoft.Extensions.PlatformAbstractions.Internal --- Microsoft.DotNet.Cli.sln | 19 ++ .../DesktopKestrelSample/src/Startup.cs | 3 +- .../TestProjects/KestrelSample/src/Startup.cs | 3 +- .../CurrentArchitecture.cs | 6 +- .../CurrentPlatform.cs | 10 +- .../project.json | 11 +- scripts/dotnet-cli-build/CompileTargets.cs | 29 ++- scripts/dotnet-cli-build/DebTargets.cs | 2 +- scripts/dotnet-cli-build/InstallerTargets.cs | 10 +- scripts/dotnet-cli-build/MsiTargets.cs | 2 +- scripts/dotnet-cli-build/PackageTargets.cs | 9 +- scripts/dotnet-cli-build/PkgTargets.cs | 2 +- scripts/dotnet-cli-build/PrepareTargets.cs | 9 +- .../dotnet-cli-build/TestPackageProjects.cs | 9 - scripts/dotnet-cli-build/Utils/Crossgen.cs | 6 +- scripts/dotnet-cli-build/Utils/Dirs.cs | 6 +- scripts/dotnet-cli-build/Utils/DotNetCli.cs | 12 +- .../AbstractPathBasedCommandResolver.cs | 9 - .../AppBaseCommandResolver.cs | 16 +- .../AppBaseDllCommandResolver.cs | 4 +- .../CompositeCommandResolver.cs | 15 +- .../DefaultCommandResolverPolicy.cs | 13 +- .../DepsJsonCommandResolver.cs | 57 ++--- .../GenericPlatformCommandSpecFactory.cs | 9 - .../IPlatformCommandSpecFactory.cs | 9 - .../OutputPathCommandResolver.cs | 11 +- .../CommandResolution/PathCommandResolver.cs | 15 +- .../ProjectDependenciesCommandResolver.cs | 4 +- .../ProjectPathCommandResolver.cs | 17 +- .../ProjectToolsCommandResolver.cs | 53 ++--- .../RootedCommandResolver.cs | 11 +- .../ScriptCommandResolverPolicy.cs | 13 +- .../WindowsExePreferredCommandSpecFactory.cs | 8 +- .../CommandResolver.cs | 32 ++- src/Microsoft.DotNet.Cli.Utils/Constants.cs | 4 +- src/Microsoft.DotNet.Cli.Utils/CoreHost.cs | 2 - src/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs | 4 +- src/Microsoft.DotNet.Cli.Utils/Env.cs | 7 +- .../EnvironmentProvider.cs | 7 +- .../IEnvironmentProvider.cs | 5 - src/Microsoft.DotNet.Cli.Utils/Muxer.cs | 2 - src/Microsoft.DotNet.Cli.Utils/PathUtility.cs | 6 +- .../ProjectDependenciesCommandFactory.cs | 4 +- src/Microsoft.DotNet.Cli.Utils/Reporter.cs | 3 - .../ScriptExecutor.cs | 5 +- .../ApplicationEnvironment.cs | 25 ++ .../Native/NativeMethods.Darwin.cs | 55 +++++ .../Native/NativeMethods.Unix.cs | 39 ++++ .../Native/NativeMethods.Windows.cs | 43 ++++ .../Native/PlatformApis.cs | 171 ++++++++++++++ .../Platform.cs | 13 ++ .../RuntimeEnvironment.cs | 104 +++++++++ .../project.json | 23 +- .../ProjectJsonWorkspace.cs | 4 +- .../FileNameSuffixes.cs | 4 +- .../ProjectContextBuilder.cs | 4 +- .../Resolution/FrameworkReferenceResolver.cs | 7 +- .../RuntimeEnvironmentRidExtensions.cs | 32 +-- .../Utilities/PathUtility.cs | 4 +- .../DependencyContext.cs | 4 +- .../DependencyContextWriter.cs | 1 - .../AppBaseCompilationAssemblyResolver.cs | 5 +- .../DotNetReferenceAssembliesPathResolver.cs | 14 +- .../PackageCompilationAssemblyResolver.cs | 14 +- .../ReferenceAssemblyPathResolver.cs | 20 +- .../project.json | 3 +- .../project.json | 1 + src/dotnet/Program.cs | 11 +- src/dotnet/Telemetry.cs | 14 +- .../commands/dotnet-build/BuildCommandApp.cs | 6 +- .../dotnet-build/DotnetProjectBuilder.cs | 5 +- .../dotnet-build/IncrementalManager.cs | 5 - .../commands/dotnet-publish/PublishCommand.cs | 10 +- src/dotnet/commands/dotnet-restore/Program.cs | 6 +- src/dotnet/commands/dotnet-run/RunCommand.cs | 4 +- src/dotnet/commands/dotnet-test/Program.cs | 4 +- .../ArgumentForwardingTests.cs | 1 - test/EndToEnd/EndToEndTest.cs | 13 +- .../GivenACompositeCommandResolver.cs | 16 +- .../GivenADefaultCommandResolver.cs | 15 +- .../GivenAPathCommandResolver.cs | 218 ------------------ ...GivenAProjectDependenciesCommandFactory.cs | 17 +- .../GivenAProjectDependencyCommandResolver.cs | 31 +-- .../GivenAProjectPathCommandResolver.cs | 31 +-- .../GivenAProjectToolsCommandResolver.cs | 40 ++-- .../GivenARootedCommandResolver.cs | 18 +- .../GivenAScriptCommandResolver.cs | 17 +- .../GivenAnAppBaseCommandResolver.cs | 25 +- .../StreamForwarderTests.cs | 22 +- .../Commands/PublishCommand.cs | 12 +- .../WindowsOnlyFactAttribute.cs | 6 +- .../PackageResolverTest.cs | 18 +- .../ReferenceAssemblyResolverTests.cs | 29 +-- test/Performance/HelloWorld.cs | 5 - .../BindingRedirectTests.cs | 8 +- .../TestSetupFixture.cs | 12 +- test/dotnet-build.Tests/BuildOutputTests.cs | 10 +- .../BuildStandAloneTests.cs | 14 +- ...boutScriptVariablesFromAManagedCompiler.cs | 11 +- .../PublishDesktopTests.cs | 11 +- test/dotnet-publish.Tests/PublishTests.cs | 11 +- .../Microsoft.DotNet.Tools.Resgen.Tests.cs | 1 - ...ntToRunTestsForMultipleTFMsInTheConsole.cs | 8 +- .../GivenThatWeWantToRunTestsInTheConsole.cs | 7 +- ...hatWeWantToUseDotnetTestE2EInDesignTime.cs | 9 +- ...otnetTestE2EInDesignTimeForMultipleTFms.cs | 14 +- test/dotnet.Tests/PackagedCommandTests.cs | 26 +-- tools/RuntimeGraphGenerator/Program.cs | 7 +- .../RuntimeGraphManager.cs | 8 +- tools/RuntimeGraphGenerator/project.json | 1 - 110 files changed, 886 insertions(+), 954 deletions(-) create mode 100644 src/Microsoft.DotNet.InternalAbstractions/ApplicationEnvironment.cs create mode 100644 src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Darwin.cs create mode 100644 src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Unix.cs create mode 100644 src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Windows.cs create mode 100644 src/Microsoft.DotNet.InternalAbstractions/Native/PlatformApis.cs create mode 100644 src/Microsoft.DotNet.InternalAbstractions/Platform.cs create mode 100644 src/Microsoft.DotNet.InternalAbstractions/RuntimeEnvironment.cs delete mode 100644 test/Microsoft.DotNet.Cli.Utils.Tests/GivenAPathCommandResolver.cs diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index b260200f1..c647f8696 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -109,6 +109,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-run.Tests", "test\do EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Performance", "test\Performance\Performance.xproj", "{6A3095FF-A7C5-4300-85A9-C025C384401D}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "binding-redirects.Tests", "test\binding-redirects.Tests\binding-redirects.Tests.xproj", "{27DBF851-F2E3-4FD5-BF4D-A73C81933283}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -777,6 +779,22 @@ Global {6A3095FF-A7C5-4300-85A9-C025C384401D}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU {6A3095FF-A7C5-4300-85A9-C025C384401D}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU {6A3095FF-A7C5-4300-85A9-C025C384401D}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Debug|Any CPU.Build.0 = Debug|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Debug|x64.ActiveCfg = Debug|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Debug|x64.Build.0 = Debug|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Release|Any CPU.ActiveCfg = Release|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Release|Any CPU.Build.0 = Release|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Release|x64.ActiveCfg = Release|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Release|x64.Build.0 = Release|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {27DBF851-F2E3-4FD5-BF4D-A73C81933283}.RelWithDebInfo|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -828,5 +846,6 @@ Global {5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {35E3C2DC-9B38-4EC5-8DD7-C32458DC485F} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {6A3095FF-A7C5-4300-85A9-C025C384401D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} + {27DBF851-F2E3-4FD5-BF4D-A73C81933283} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} EndGlobalSection EndGlobal diff --git a/TestAssets/DesktopTestProjects/DesktopKestrelSample/src/Startup.cs b/TestAssets/DesktopTestProjects/DesktopKestrelSample/src/Startup.cs index 4c6b0bead..4015cb438 100644 --- a/TestAssets/DesktopTestProjects/DesktopKestrelSample/src/Startup.cs +++ b/TestAssets/DesktopTestProjects/DesktopKestrelSample/src/Startup.cs @@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.PlatformAbstractions; namespace SampleApp { @@ -21,7 +20,7 @@ namespace SampleApp private static string Args { get; set; } private static CancellationTokenSource ServerCancellationTokenSource { get; set; } - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env) + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { var ksi = app.ServerFeatures.Get(); ksi.NoDelay = true; diff --git a/TestAssets/TestProjects/KestrelSample/src/Startup.cs b/TestAssets/TestProjects/KestrelSample/src/Startup.cs index 4c6b0bead..4015cb438 100644 --- a/TestAssets/TestProjects/KestrelSample/src/Startup.cs +++ b/TestAssets/TestProjects/KestrelSample/src/Startup.cs @@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.PlatformAbstractions; namespace SampleApp { @@ -21,7 +20,7 @@ namespace SampleApp private static string Args { get; set; } private static CancellationTokenSource ServerCancellationTokenSource { get; set; } - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env) + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { var ksi = app.ServerFeatures.Get(); ksi.NoDelay = true; diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentArchitecture.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentArchitecture.cs index 71aedf03c..12212033a 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentArchitecture.cs +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentArchitecture.cs @@ -1,5 +1,5 @@ using System; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Cli.Build.Framework { @@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework { get { - var archName = PlatformServices.Default.Runtime.RuntimeArchitecture; + var archName = RuntimeEnvironment.RuntimeArchitecture; return string.Equals(archName, "x86", StringComparison.OrdinalIgnoreCase); } } @@ -26,7 +26,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework { get { - var archName = PlatformServices.Default.Runtime.RuntimeArchitecture; + var archName = RuntimeEnvironment.RuntimeArchitecture; return string.Equals(archName, "x64", StringComparison.OrdinalIgnoreCase); } } diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs b/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs index 7e7ab0300..b232c92dd 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs @@ -1,6 +1,6 @@ using System; using System.Runtime.InteropServices; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Cli.Build.Framework { @@ -34,7 +34,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework { get { - var osname = PlatformServices.Default.Runtime.OperatingSystem; + var osname = RuntimeEnvironment.OperatingSystem; return string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase); } } @@ -43,7 +43,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework { get { - var osname = PlatformServices.Default.Runtime.OperatingSystem; + var osname = RuntimeEnvironment.OperatingSystem; return string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase); } } @@ -52,7 +52,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework { get { - var osname = PlatformServices.Default.Runtime.OperatingSystem; + var osname = RuntimeEnvironment.OperatingSystem; return string.Equals(osname, "rhel", StringComparison.OrdinalIgnoreCase); } } @@ -69,7 +69,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework { get { - var osname = PlatformServices.Default.Runtime.OperatingSystem; + var osname = RuntimeEnvironment.OperatingSystem; return string.Equals(osname, "debian", StringComparison.OrdinalIgnoreCase); } } diff --git a/scripts/Microsoft.DotNet.Cli.Build.Framework/project.json b/scripts/Microsoft.DotNet.Cli.Build.Framework/project.json index e46ec9bea..0f88b1650 100644 --- a/scripts/Microsoft.DotNet.Cli.Build.Framework/project.json +++ b/scripts/Microsoft.DotNet.Cli.Build.Framework/project.json @@ -1,10 +1,19 @@ { "version": "1.0.0-*", + "compilationOptions": { + "warningsAsErrors": true, + "allowUnsafe": true + }, "dependencies": { "NETStandard.Library": "1.5.0-rc2-24027", "System.Diagnostics.Process": "4.1.0-rc2-24027", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-20581" + "System.Reflection.TypeExtensions": "4.1.0-rc2-24027" }, + "compile": [ + "../../src/Microsoft.DotNet.InternalAbstractions/RuntimeEnvironment.cs", + "../../src/Microsoft.DotNet.InternalAbstractions/Platform.cs", + "../../src/Microsoft.DotNet.InternalAbstractions/Native/*.cs" + ], "frameworks": { "netstandard1.3": { "imports": "dnxcore50" diff --git a/scripts/dotnet-cli-build/CompileTargets.cs b/scripts/dotnet-cli-build/CompileTargets.cs index 8322e9107..b2ab372d8 100644 --- a/scripts/dotnet-cli-build/CompileTargets.cs +++ b/scripts/dotnet-cli-build/CompileTargets.cs @@ -1,18 +1,15 @@ using System; using System.Collections.Generic; using System.IO; -using System.Text; using System.Linq; using System.Runtime.InteropServices; +using System.Text; using Microsoft.DotNet.Cli.Build.Framework; -using Microsoft.Extensions.PlatformAbstractions; - -using static Microsoft.DotNet.Cli.Build.FS; -using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; -using System.Text.RegularExpressions; -using System.Reflection.PortableExecutable; -using Newtonsoft.Json.Linq; +using Microsoft.DotNet.InternalAbstractions; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; +using static Microsoft.DotNet.Cli.Build.FS; namespace Microsoft.DotNet.Cli.Build { @@ -37,9 +34,9 @@ namespace Microsoft.DotNet.Cli.Build }; public static string HostPackagePlatformRid => HostPackageSupportedRids[ - (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) - ? $"win7-{PlatformServices.Default.Runtime.RuntimeArchitecture}" - : PlatformServices.Default.Runtime.GetRuntimeIdentifier()]; + (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) + ? $"win7-{RuntimeEnvironment.RuntimeArchitecture}" + : RuntimeEnvironment.GetRuntimeIdentifier()]; public static readonly Dictionary HostPackageSupportedRids = new Dictionary() { @@ -479,13 +476,13 @@ namespace Microsoft.DotNet.Cli.Build string SharedFrameworkNugetVersion = c.BuildContext.Get("SharedFrameworkNugetVersion"); string sharedFrameworkRid; - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { - sharedFrameworkRid = $"win7-{PlatformServices.Default.Runtime.RuntimeArchitecture}"; + sharedFrameworkRid = $"win7-{RuntimeEnvironment.RuntimeArchitecture}"; } else { - sharedFrameworkRid = PlatformServices.Default.Runtime.GetRuntimeIdentifier(); + sharedFrameworkRid = RuntimeEnvironment.GetRuntimeIdentifier(); } string SharedFrameworkSourceRoot = GenerateSharedFrameworkProject(c, SharedFrameworkTemplateSourceRoot, sharedFrameworkRid); @@ -524,7 +521,7 @@ namespace Microsoft.DotNet.Cli.Build // Generate RID fallback graph string runtimeGraphGeneratorRuntime = null; - switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) + switch (RuntimeEnvironment.OperatingSystemPlatform) { case Platform.Windows: runtimeGraphGeneratorRuntime = "win"; @@ -553,7 +550,7 @@ namespace Microsoft.DotNet.Cli.Build } else { - c.Error($"Could not determine rid graph generation runtime for platform {PlatformServices.Default.Runtime.OperatingSystemPlatform}"); + c.Error($"Could not determine rid graph generation runtime for platform {RuntimeEnvironment.OperatingSystemPlatform}"); } File.Copy( diff --git a/scripts/dotnet-cli-build/DebTargets.cs b/scripts/dotnet-cli-build/DebTargets.cs index 37ff9211e..f9daff95c 100644 --- a/scripts/dotnet-cli-build/DebTargets.cs +++ b/scripts/dotnet-cli-build/DebTargets.cs @@ -4,7 +4,7 @@ using System.IO; using System.IO.Compression; using System.Runtime.InteropServices; using Microsoft.DotNet.Cli.Build.Framework; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; diff --git a/scripts/dotnet-cli-build/InstallerTargets.cs b/scripts/dotnet-cli-build/InstallerTargets.cs index fcea28e86..f520d40e1 100644 --- a/scripts/dotnet-cli-build/InstallerTargets.cs +++ b/scripts/dotnet-cli-build/InstallerTargets.cs @@ -1,12 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Compression; -using System.Runtime.InteropServices; -using Microsoft.DotNet.Cli.Build.Framework; -using Microsoft.Extensions.PlatformAbstractions; - -using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; +using Microsoft.DotNet.Cli.Build.Framework; namespace Microsoft.DotNet.Cli.Build { diff --git a/scripts/dotnet-cli-build/MsiTargets.cs b/scripts/dotnet-cli-build/MsiTargets.cs index 8161496e4..dfb6ee39f 100644 --- a/scripts/dotnet-cli-build/MsiTargets.cs +++ b/scripts/dotnet-cli-build/MsiTargets.cs @@ -5,7 +5,7 @@ using System.IO.Compression; using System.Net.Http; using System.Runtime.InteropServices; using Microsoft.DotNet.Cli.Build.Framework; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; diff --git a/scripts/dotnet-cli-build/PackageTargets.cs b/scripts/dotnet-cli-build/PackageTargets.cs index 803f64115..e524b1166 100644 --- a/scripts/dotnet-cli-build/PackageTargets.cs +++ b/scripts/dotnet-cli-build/PackageTargets.cs @@ -4,8 +4,7 @@ using System.IO; using System.IO.Compression; using System.Runtime.InteropServices; using Microsoft.DotNet.Cli.Build.Framework; -using Microsoft.Extensions.PlatformAbstractions; - +using Microsoft.DotNet.InternalAbstractions; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; namespace Microsoft.DotNet.Cli.Build @@ -261,11 +260,11 @@ namespace Microsoft.DotNet.Cli.Build // This is overkill, but I want to cover all the variables used in all OSes (including where some have the same names) var buildVersion = c.BuildContext.Get("BuildVersion"); var configuration = c.BuildContext.Get("Configuration"); - var architecture = PlatformServices.Default.Runtime.RuntimeArchitecture; + var architecture = RuntimeEnvironment.RuntimeArchitecture; var env = new Dictionary() { - { "RID", PlatformServices.Default.Runtime.GetRuntimeIdentifier() }, - { "OSNAME", PlatformServices.Default.Runtime.OperatingSystem }, + { "RID", RuntimeEnvironment.GetRuntimeIdentifier() }, + { "OSNAME", RuntimeEnvironment.OperatingSystem }, { "TFM", "dnxcore50" }, { "REPOROOT", Dirs.RepoRoot }, { "OutputDir", Dirs.Output }, diff --git a/scripts/dotnet-cli-build/PkgTargets.cs b/scripts/dotnet-cli-build/PkgTargets.cs index 1460ba3f8..b539fe59a 100644 --- a/scripts/dotnet-cli-build/PkgTargets.cs +++ b/scripts/dotnet-cli-build/PkgTargets.cs @@ -4,7 +4,7 @@ using System.IO; using System.IO.Compression; using System.Runtime.InteropServices; using Microsoft.DotNet.Cli.Build.Framework; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; diff --git a/scripts/dotnet-cli-build/PrepareTargets.cs b/scripts/dotnet-cli-build/PrepareTargets.cs index 98898aa73..f36f07e69 100644 --- a/scripts/dotnet-cli-build/PrepareTargets.cs +++ b/scripts/dotnet-cli-build/PrepareTargets.cs @@ -7,8 +7,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using Microsoft.DotNet.Cli.Build.Framework; -using Microsoft.Extensions.PlatformAbstractions; -using Newtonsoft.Json; +using Microsoft.DotNet.InternalAbstractions; using Newtonsoft.Json.Linq; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; using static Microsoft.DotNet.Cli.Build.FS; @@ -37,8 +36,6 @@ namespace Microsoft.DotNet.Cli.Build [Target(nameof(GenerateVersions), nameof(UpdateTemplateVersions), nameof(CheckPrereqs), nameof(LocateStage0), nameof(ExpectedBuildArtifacts))] public static BuildTargetResult Init(BuildTargetContext c) { - var runtimeInfo = PlatformServices.Default.Runtime; - var configEnv = Environment.GetEnvironmentVariable("CONFIGURATION"); if (string.IsNullOrEmpty(configEnv)) @@ -51,8 +48,8 @@ namespace Microsoft.DotNet.Cli.Build c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}"); c.Info("Build Environment:"); - c.Info($" Operating System: {runtimeInfo.OperatingSystem} {runtimeInfo.OperatingSystemVersion}"); - c.Info($" Platform: {runtimeInfo.OperatingSystemPlatform}"); + c.Info($" Operating System: {RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}"); + c.Info($" Platform: {RuntimeEnvironment.OperatingSystemPlatform}"); return c.Success(); } diff --git a/scripts/dotnet-cli-build/TestPackageProjects.cs b/scripts/dotnet-cli-build/TestPackageProjects.cs index ff7829be0..dbe5d42b6 100644 --- a/scripts/dotnet-cli-build/TestPackageProjects.cs +++ b/scripts/dotnet-cli-build/TestPackageProjects.cs @@ -1,14 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; using Microsoft.DotNet.Cli.Build.Framework; -using static Microsoft.DotNet.Cli.Build.FS; -using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; -using static Microsoft.DotNet.Cli.Build.Utils; - namespace Microsoft.DotNet.Cli.Build { public static class TestPackageProjects diff --git a/scripts/dotnet-cli-build/Utils/Crossgen.cs b/scripts/dotnet-cli-build/Utils/Crossgen.cs index ce6a24bf7..2740acdbc 100644 --- a/scripts/dotnet-cli-build/Utils/Crossgen.cs +++ b/scripts/dotnet-cli-build/Utils/Crossgen.cs @@ -2,10 +2,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using Microsoft.DotNet.Cli.Build.Framework; -using Microsoft.Extensions.PlatformAbstractions; - +using Microsoft.DotNet.InternalAbstractions; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; namespace Microsoft.DotNet.Cli.Build @@ -28,7 +26,7 @@ namespace Microsoft.DotNet.Cli.Build private string GetCrossgenPathForVersion() { - string arch = PlatformServices.Default.Runtime.RuntimeArchitecture; + string arch = RuntimeEnvironment.RuntimeArchitecture; string packageId; if (CurrentPlatform.IsWindows) { diff --git a/scripts/dotnet-cli-build/Utils/Dirs.cs b/scripts/dotnet-cli-build/Utils/Dirs.cs index 71a98f4b6..f812887ef 100644 --- a/scripts/dotnet-cli-build/Utils/Dirs.cs +++ b/scripts/dotnet-cli-build/Utils/Dirs.cs @@ -1,7 +1,7 @@ -using Microsoft.Extensions.PlatformAbstractions; -using System; +using System; using System.IO; using System.Runtime.InteropServices; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Cli.Build { @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Cli.Build public static readonly string Output = Path.Combine( RepoRoot, "artifacts", - PlatformServices.Default.Runtime.GetRuntimeIdentifier()); + RuntimeEnvironment.GetRuntimeIdentifier()); public static readonly string Intermediate = Path.Combine(Output, "intermediate"); public static readonly string PackagesIntermediate = Path.Combine(Output, "packages/intermediate"); diff --git a/scripts/dotnet-cli-build/Utils/DotNetCli.cs b/scripts/dotnet-cli-build/Utils/DotNetCli.cs index c18011d1c..eb4966dbe 100644 --- a/scripts/dotnet-cli-build/Utils/DotNetCli.cs +++ b/scripts/dotnet-cli-build/Utils/DotNetCli.cs @@ -1,8 +1,8 @@ -using Microsoft.DotNet.Cli.Build.Framework; -using Microsoft.Extensions.PlatformAbstractions; -using System.IO; +using System.IO; using System.Linq; using System.Runtime.InteropServices; +using Microsoft.DotNet.Cli.Build.Framework; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Cli.Build { @@ -43,12 +43,12 @@ namespace Microsoft.DotNet.Cli.Build if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0", - PlatformServices.Default.Runtime.OperatingSystemPlatform.ToString(), - PlatformServices.Default.Runtime.RuntimeArchitecture); + RuntimeEnvironment.OperatingSystemPlatform.ToString(), + RuntimeEnvironment.RuntimeArchitecture); } else { - return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0", PlatformServices.Default.Runtime.OperatingSystemPlatform.ToString()); + return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0", RuntimeEnvironment.OperatingSystemPlatform.ToString()); } } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AbstractPathBasedCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AbstractPathBasedCommandResolver.cs index 3ac3ce450..a9949d26a 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AbstractPathBasedCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AbstractPathBasedCommandResolver.cs @@ -1,13 +1,4 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; namespace Microsoft.DotNet.Cli.Utils { public abstract class AbstractPathBasedCommandResolver : ICommandResolver diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AppBaseCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AppBaseCommandResolver.cs index 26668183f..cdf6104cf 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AppBaseCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AppBaseCommandResolver.cs @@ -1,24 +1,16 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; +using Microsoft.DotNet.InternalAbstractions; + namespace Microsoft.DotNet.Cli.Utils { public class AppBaseCommandResolver : AbstractPathBasedCommandResolver { - public AppBaseCommandResolver(IEnvironmentProvider environment, + public AppBaseCommandResolver(IEnvironmentProvider environment, IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { } internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments) { return _environment.GetCommandPathFromRootPath( - PlatformServices.Default.Application.ApplicationBasePath, + ApplicationEnvironment.ApplicationBasePath, commandResolverArguments.CommandName); } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AppBaseDllCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AppBaseDllCommandResolver.cs index 8d613038e..33604c4b4 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AppBaseDllCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/AppBaseDllCommandResolver.cs @@ -1,7 +1,7 @@ using System.IO; using System.Linq; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Cli.Utils { @@ -15,7 +15,7 @@ namespace Microsoft.DotNet.Cli.Utils } if (commandResolverArguments.CommandName.EndsWith(FileNameSuffixes.DotNet.DynamicLib)) { - var localPath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, + var localPath = Path.Combine(ApplicationEnvironment.ApplicationBasePath, commandResolverArguments.CommandName); if (File.Exists(localPath)) { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/CompositeCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/CompositeCommandResolver.cs index 71bb589dc..bce8811f3 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/CompositeCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/CompositeCommandResolver.cs @@ -1,13 +1,4 @@ -using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; namespace Microsoft.DotNet.Cli.Utils { @@ -15,9 +6,9 @@ namespace Microsoft.DotNet.Cli.Utils { private IList _orderedCommandResolvers; - public IEnumerable OrderedCommandResolvers + public IEnumerable OrderedCommandResolvers { - get + get { return _orderedCommandResolvers; } @@ -32,7 +23,7 @@ namespace Microsoft.DotNet.Cli.Utils { _orderedCommandResolvers.Add(commandResolver); } - + public CommandSpec Resolve(CommandResolverArguments commandResolverArguments) { foreach (var commandResolver in _orderedCommandResolvers) diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DefaultCommandResolverPolicy.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DefaultCommandResolverPolicy.cs index b094663e2..b4b21fada 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DefaultCommandResolverPolicy.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DefaultCommandResolverPolicy.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Cli.Utils { @@ -19,7 +10,7 @@ namespace Microsoft.DotNet.Cli.Utils var packagedCommandSpecFactory = new PackagedCommandSpecFactory(); var platformCommandSpecFactory = default(IPlatformCommandSpecFactory); - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DepsJsonCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DepsJsonCommandResolver.cs index f4b54347c..6c67bd2b1 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DepsJsonCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DepsJsonCommandResolver.cs @@ -2,26 +2,15 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.Extensions.DependencyModel; -using Microsoft.Extensions.PlatformAbstractions; -using Microsoft.DotNet.ProjectModel.Resolution; -using NuGet.Frameworks; -using NuGet.Packaging; -using NuGet.ProjectModel; - -using LockFile = Microsoft.DotNet.ProjectModel.Graph.LockFile; -using FileFormatException = Microsoft.DotNet.ProjectModel.FileFormatException; namespace Microsoft.DotNet.Cli.Utils { public class DepsJsonCommandResolver : ICommandResolver { - private static readonly string[] s_extensionPreferenceOrder = new [] - { + private static readonly string[] s_extensionPreferenceOrder = new[] + { "", ".exe", ".dll" @@ -30,7 +19,7 @@ namespace Microsoft.DotNet.Cli.Utils private string _nugetPackageRoot; private Muxer _muxer; - public DepsJsonCommandResolver(string nugetPackageRoot) + public DepsJsonCommandResolver(string nugetPackageRoot) : this(new Muxer(), nugetPackageRoot) { } public DepsJsonCommandResolver(Muxer muxer, string nugetPackageRoot) @@ -46,16 +35,16 @@ namespace Microsoft.DotNet.Cli.Utils { return null; } - + return ResolveFromDepsJsonFile( - commandResolverArguments.CommandName, + commandResolverArguments.CommandName, commandResolverArguments.CommandArguments.OrEmptyIfNull(), commandResolverArguments.DepsJsonFile); } private CommandSpec ResolveFromDepsJsonFile( - string commandName, - IEnumerable commandArgs, + string commandName, + IEnumerable commandArgs, string depsJsonFile) { var dependencyContext = LoadDependencyContextFromFile(depsJsonFile); @@ -67,8 +56,8 @@ namespace Microsoft.DotNet.Cli.Utils } return CreateCommandSpecUsingMuxerIfPortable( - commandPath, - commandArgs, + commandPath, + commandArgs, depsJsonFile, CommandResolutionStrategy.DepsFile, _nugetPackageRoot, @@ -93,11 +82,11 @@ namespace Microsoft.DotNet.Cli.Utils var commandCandidates = new List(); var assemblyCommandCandidates = GetCommandCandidates( - commandName, - dependencyContext, + commandName, + dependencyContext, CommandCandidateType.RuntimeCommandCandidate); var nativeCommandCandidates = GetCommandCandidates( - commandName, + commandName, dependencyContext, CommandCandidateType.NativeCommandCandidate); @@ -110,7 +99,7 @@ namespace Microsoft.DotNet.Cli.Utils } private IEnumerable GetCommandCandidates( - string commandName, + string commandName, DependencyContext dependencyContext, CommandCandidateType commandCandidateType) { @@ -133,7 +122,7 @@ namespace Microsoft.DotNet.Cli.Utils commandName, runtimeAssetGroups, runtimeLibrary.Name, - runtimeLibrary.Version)); + runtimeLibrary.Version)); } return commandCandidates; @@ -141,14 +130,14 @@ namespace Microsoft.DotNet.Cli.Utils private IEnumerable GetCommandCandidatesFromRuntimeAssetGroups( string commandName, - IEnumerable runtimeAssetGroups, + IEnumerable runtimeAssetGroups, string PackageName, string PackageVersion) { var candidateAssetGroups = runtimeAssetGroups .Where(r => r.Runtime == string.Empty) - .Where(a => - a.AssetPaths.Any(p => + .Where(a => + a.AssetPaths.Any(p => Path.GetFileNameWithoutExtension(p).Equals(commandName, StringComparison.OrdinalIgnoreCase))); var commandCandidates = new List(); @@ -190,9 +179,9 @@ namespace Microsoft.DotNet.Cli.Utils } private CommandSpec CreateCommandSpecUsingMuxerIfPortable( - string commandPath, - IEnumerable commandArgs, - string depsJsonFile, + string commandPath, + IEnumerable commandArgs, + string depsJsonFile, CommandResolutionStrategy commandResolutionStrategy, string nugetPackagesRoot, bool isPortable) @@ -248,9 +237,9 @@ namespace Microsoft.DotNet.Cli.Utils public string GetAbsoluteCommandPath(string nugetPackageRoot) { return Path.Combine( - nugetPackageRoot.Replace('/', Path.DirectorySeparatorChar), - PackageName.Replace('/', Path.DirectorySeparatorChar), - PackageVersion.Replace('/', Path.DirectorySeparatorChar), + nugetPackageRoot.Replace('/', Path.DirectorySeparatorChar), + PackageName.Replace('/', Path.DirectorySeparatorChar), + PackageVersion.Replace('/', Path.DirectorySeparatorChar), RelativeCommandPath.Replace('/', Path.DirectorySeparatorChar)); } } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/GenericPlatformCommandSpecFactory.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/GenericPlatformCommandSpecFactory.cs index eea6365e4..9472eb67c 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/GenericPlatformCommandSpecFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/GenericPlatformCommandSpecFactory.cs @@ -1,13 +1,4 @@ -using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPlatformCommandSpecFactory.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPlatformCommandSpecFactory.cs index 1463bc9ec..3748a9131 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPlatformCommandSpecFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPlatformCommandSpecFactory.cs @@ -1,13 +1,4 @@ -using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/OutputPathCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/OutputPathCommandResolver.cs index da7ce99b1..a8d5b2333 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/OutputPathCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/OutputPathCommandResolver.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime.InteropServices; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; -using NuGet.Packaging; namespace Microsoft.DotNet.Cli.Utils { @@ -78,7 +73,7 @@ namespace Microsoft.DotNet.Cli.Utils var projectContext = ProjectContext.Create( projectRootPath, framework, - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); if (projectContext.RuntimeIdentifier == null) { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PathCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PathCommandResolver.cs index a1e63c801..1a263d820 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PathCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PathCommandResolver.cs @@ -1,19 +1,8 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; - -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.Utils { public class PathCommandResolver : AbstractPathBasedCommandResolver { - public PathCommandResolver(IEnvironmentProvider environment, + public PathCommandResolver(IEnvironmentProvider environment, IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { } internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments) diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs index 9cd097fe2..63b094661 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; namespace Microsoft.DotNet.Cli.Utils @@ -128,7 +128,7 @@ namespace Microsoft.DotNet.Cli.Utils return ProjectContext.Create( projectRootPath, framework, - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectPathCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectPathCommandResolver.cs index d857ba890..720e406a3 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectPathCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectPathCommandResolver.cs @@ -1,19 +1,8 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; - -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.Utils { public class ProjectPathCommandResolver : AbstractPathBasedCommandResolver { - public ProjectPathCommandResolver(IEnvironmentProvider environment, + public ProjectPathCommandResolver(IEnvironmentProvider environment, IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { } internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments) @@ -24,7 +13,7 @@ namespace Microsoft.DotNet.Cli.Utils } return _environment.GetCommandPathFromRootPath( - commandResolverArguments.ProjectDirectory, + commandResolverArguments.ProjectDirectory, commandResolverArguments.CommandName, commandResolverArguments.InferredExtensions.OrEmptyIfNull()); } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs index 374d48b51..753b079d0 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs @@ -2,29 +2,24 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.Extensions.DependencyModel; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; -using NuGet.Packaging; -using NuGet.ProjectModel; - -using LockFile = Microsoft.DotNet.ProjectModel.Graph.LockFile; using FileFormatException = Microsoft.DotNet.ProjectModel.FileFormatException; +using LockFile = Microsoft.DotNet.ProjectModel.Graph.LockFile; namespace Microsoft.DotNet.Cli.Utils { public class ProjectToolsCommandResolver : ICommandResolver { private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetCoreApp10; - - private static readonly CommandResolutionStrategy s_commandResolutionStrategy = + + private static readonly CommandResolutionStrategy s_commandResolutionStrategy = CommandResolutionStrategy.ProjectToolsPackage; - private static readonly string s_currentRuntimeIdentifier = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + private static readonly string s_currentRuntimeIdentifier = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); private List _allowedCommandExtensions; @@ -34,7 +29,7 @@ namespace Microsoft.DotNet.Cli.Utils { _packagedCommandSpecFactory = packagedCommandSpecFactory; - _allowedCommandExtensions = new List() + _allowedCommandExtensions = new List() { FileNameSuffixes.DotNet.DynamicLib }; @@ -47,15 +42,15 @@ namespace Microsoft.DotNet.Cli.Utils { return null; } - + return ResolveFromProjectTools( - commandResolverArguments.CommandName, + commandResolverArguments.CommandName, commandResolverArguments.CommandArguments.OrEmptyIfNull(), commandResolverArguments.ProjectDirectory); } private CommandSpec ResolveFromProjectTools( - string commandName, + string commandName, IEnumerable args, string projectDirectory) { @@ -70,7 +65,7 @@ namespace Microsoft.DotNet.Cli.Utils return ResolveCommandSpecFromAllToolLibraries( toolsLibraries, - commandName, + commandName, args, projectContext); } @@ -101,7 +96,7 @@ namespace Microsoft.DotNet.Cli.Utils ProjectContext projectContext) { var nugetPackagesRoot = projectContext.PackagesDirectory; - + var lockFile = GetToolLockFile(toolLibraryRange, nugetPackagesRoot); var toolLibrary = lockFile.Targets @@ -112,10 +107,10 @@ namespace Microsoft.DotNet.Cli.Utils { return null; } - + var depsFileRoot = Path.GetDirectoryName(lockFile.LockFilePath); var depsFilePath = GetToolDepsFilePath(toolLibraryRange, lockFile, depsFileRoot); - + return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary( toolLibrary, commandName, @@ -159,8 +154,8 @@ namespace Microsoft.DotNet.Cli.Utils var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot); return toolPathCalculator.GetBestLockFilePath( - toolLibrary.Name, - toolLibrary.VersionRange, + toolLibrary.Name, + toolLibrary.VersionRange, s_toolPackageFramework); } @@ -182,8 +177,8 @@ namespace Microsoft.DotNet.Cli.Utils } private string GetToolDepsFilePath( - LibraryRange toolLibrary, - LockFile toolLockFile, + LibraryRange toolLibrary, + LockFile toolLockFile, string depsPathRoot) { var depsJsonPath = Path.Combine( @@ -196,7 +191,7 @@ namespace Microsoft.DotNet.Cli.Utils } private void EnsureToolJsonDepsFileExists( - LockFile toolLockFile, + LockFile toolLockFile, string depsPath) { if (!File.Exists(depsPath)) @@ -207,7 +202,7 @@ namespace Microsoft.DotNet.Cli.Utils // Need to unit test this, so public public void GenerateDepsJsonFile( - LockFile toolLockFile, + LockFile toolLockFile, string depsPath) { Reporter.Verbose.WriteLine($"Generating deps.json at: {depsPath}"); @@ -220,11 +215,11 @@ namespace Microsoft.DotNet.Cli.Utils var exporter = projectContext.CreateExporter(Constants.DefaultConfiguration); var dependencyContext = new DependencyContextBuilder() - .Build(null, - null, + .Build(null, + null, exporter.GetAllExports(), - true, - s_toolPackageFramework, + true, + s_toolPackageFramework, string.Empty); var tempDepsFile = Path.GetTempFileName(); @@ -250,7 +245,7 @@ namespace Microsoft.DotNet.Cli.Utils File.Delete(tempDepsFile); } catch (Exception e2) - { + { Reporter.Verbose.WriteLine($"unable to delete temporary deps.json file: {e2.Message}"); } } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/RootedCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/RootedCommandResolver.cs index f5a6d08a1..d7dac8b6c 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/RootedCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/RootedCommandResolver.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; +using System.IO; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ScriptCommandResolverPolicy.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ScriptCommandResolverPolicy.cs index 4fa2b456f..04878c5a5 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ScriptCommandResolverPolicy.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ScriptCommandResolverPolicy.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Cli.Utils { @@ -18,7 +9,7 @@ namespace Microsoft.DotNet.Cli.Utils var environment = new EnvironmentProvider(); var platformCommandSpecFactory = default(IPlatformCommandSpecFactory); - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/WindowsExePreferredCommandSpecFactory.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/WindowsExePreferredCommandSpecFactory.cs index aacd356b9..4619f5bea 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/WindowsExePreferredCommandSpecFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/WindowsExePreferredCommandSpecFactory.cs @@ -2,12 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; -using NuGet.Frameworks; -using NuGet.Packaging; namespace Microsoft.DotNet.Cli.Utils { @@ -36,7 +30,7 @@ namespace Microsoft.DotNet.Cli.Utils } } - return useCmdWrapper + return useCmdWrapper ? CreateCommandSpecWrappedWithCmd(commandPath, args, resolutionStrategy) : CreateCommandSpecFromExecutable(commandPath, args, resolutionStrategy); } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolver.cs index 6c797b4a1..35f2f3cd5 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolver.cs @@ -1,24 +1,18 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime.InteropServices; using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; -using NuGet.Packaging; namespace Microsoft.DotNet.Cli.Utils { internal static class CommandResolver { public static CommandSpec TryResolveCommandSpec( - string commandName, - IEnumerable args, - NuGetFramework framework = null, - string configuration=Constants.DefaultConfiguration, - string outputPath=null) + string commandName, + IEnumerable args, + NuGetFramework framework = null, + string configuration = Constants.DefaultConfiguration, + string outputPath = null) { var commandResolverArgs = new CommandResolverArguments { @@ -29,16 +23,16 @@ namespace Microsoft.DotNet.Cli.Utils Configuration = configuration, OutputPath = outputPath }; - + var defaultCommandResolver = DefaultCommandResolverPolicy.Create(); - + return defaultCommandResolver.Resolve(commandResolverArgs); } - + public static CommandSpec TryResolveScriptCommandSpec( - string commandName, - IEnumerable args, - Project project, + string commandName, + IEnumerable args, + Project project, string[] inferredExtensionList) { var commandResolverArgs = new CommandResolverArguments @@ -50,7 +44,7 @@ namespace Microsoft.DotNet.Cli.Utils }; var scriptCommandResolver = ScriptCommandResolverPolicy.Create(); - + return scriptCommandResolver.Resolve(commandResolverArgs); } } diff --git a/src/Microsoft.DotNet.Cli.Utils/Constants.cs b/src/Microsoft.DotNet.Cli.Utils/Constants.cs index d1411c7c3..1d10032ab 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Constants.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Constants.cs @@ -1,13 +1,13 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Cli.Utils { public static class Constants { - private static Platform CurrentPlatform => PlatformServices.Default.Runtime.OperatingSystemPlatform; + private static Platform CurrentPlatform => RuntimeEnvironment.OperatingSystemPlatform; public const string DefaultConfiguration = "Debug"; public static readonly string ProjectFileName = "project.json"; diff --git a/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs b/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs index 341321ac8..2424bf65f 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs @@ -1,7 +1,5 @@ using System; using System.IO; -using System.Reflection; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs b/src/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs index a676723cc..d55857038 100644 --- a/src/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs +++ b/src/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs @@ -4,7 +4,7 @@ using System; using System.IO; using System.Reflection; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Cli.Utils { @@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Utils { var content = File.ReadAllText(DotnetFiles.VersionFile); content += Environment.NewLine; - content += PlatformServices.Default.Runtime.GetRuntimeIdentifier(); + content += RuntimeEnvironment.GetRuntimeIdentifier(); return content; } } diff --git a/src/Microsoft.DotNet.Cli.Utils/Env.cs b/src/Microsoft.DotNet.Cli.Utils/Env.cs index 5d0d1382b..20e9e43b2 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Env.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Env.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.Extensions.PlatformAbstractions; +using System.Collections.Generic; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs b/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs index b44ffef71..aa7334532 100644 --- a/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs +++ b/src/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs @@ -2,8 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Cli.Utils { @@ -19,7 +18,7 @@ namespace Microsoft.DotNet.Cli.Utils if (_executableExtensions == null) { - _executableExtensions = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows + _executableExtensions = RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows ? Environment.GetEnvironmentVariable("PATHEXT") .Split(';') .Select(e => e.ToLower().Trim('"')) @@ -36,7 +35,7 @@ namespace Microsoft.DotNet.Cli.Utils { if (_searchPaths == null) { - var searchPaths = new List { PlatformServices.Default.Application.ApplicationBasePath }; + var searchPaths = new List { ApplicationEnvironment.ApplicationBasePath }; searchPaths.AddRange(Environment .GetEnvironmentVariable("PATH") diff --git a/src/Microsoft.DotNet.Cli.Utils/IEnvironmentProvider.cs b/src/Microsoft.DotNet.Cli.Utils/IEnvironmentProvider.cs index 754bf54a3..e9cc613c7 100644 --- a/src/Microsoft.DotNet.Cli.Utils/IEnvironmentProvider.cs +++ b/src/Microsoft.DotNet.Cli.Utils/IEnvironmentProvider.cs @@ -1,9 +1,4 @@ -using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/Muxer.cs b/src/Microsoft.DotNet.Cli.Utils/Muxer.cs index fe0a1fb9d..a2387c1ba 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Muxer.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Muxer.cs @@ -1,7 +1,5 @@ using System; using System.IO; -using Microsoft.Extensions.PlatformAbstractions; -using System.Diagnostics; using System.Reflection; namespace Microsoft.DotNet.Cli.Utils diff --git a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs index 691c4f560..5be91d7a4 100644 --- a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs +++ b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs @@ -3,7 +3,7 @@ using System; using System.IO; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Tools.Common { @@ -98,7 +98,7 @@ namespace Microsoft.DotNet.Tools.Common } StringComparison compare; - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { compare = StringComparison.OrdinalIgnoreCase; // check if paths are on the same volume @@ -216,7 +216,7 @@ namespace Microsoft.DotNet.Tools.Common { var comparison = StringComparison.Ordinal; - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { comparison = StringComparison.OrdinalIgnoreCase; } diff --git a/src/Microsoft.DotNet.Cli.Utils/ProjectDependenciesCommandFactory.cs b/src/Microsoft.DotNet.Cli.Utils/ProjectDependenciesCommandFactory.cs index 29793e178..0f5cb31cf 100644 --- a/src/Microsoft.DotNet.Cli.Utils/ProjectDependenciesCommandFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/ProjectDependenciesCommandFactory.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; using NuGet.Frameworks; namespace Microsoft.DotNet.Cli.Utils @@ -100,7 +100,7 @@ namespace Microsoft.DotNet.Cli.Utils if (framework.IsDesktop()) { IPlatformCommandSpecFactory platformCommandSpecFactory = null; - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); } diff --git a/src/Microsoft.DotNet.Cli.Utils/Reporter.cs b/src/Microsoft.DotNet.Cli.Utils/Reporter.cs index 4e85c672b..0afffa16a 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Reporter.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Reporter.cs @@ -1,9 +1,6 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using Microsoft.Extensions.PlatformAbstractions; - namespace Microsoft.DotNet.Cli.Utils { // Stupid-simple console manager diff --git a/src/Microsoft.DotNet.Cli.Utils/ScriptExecutor.cs b/src/Microsoft.DotNet.Cli.Utils/ScriptExecutor.cs index 8f8f91b73..e2dbd3b4d 100644 --- a/src/Microsoft.DotNet.Cli.Utils/ScriptExecutor.cs +++ b/src/Microsoft.DotNet.Cli.Utils/ScriptExecutor.cs @@ -1,10 +1,9 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using Microsoft.DotNet.Cli.Utils.CommandParsing; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Cli.Utils { @@ -48,7 +47,7 @@ namespace Microsoft.DotNet.Cli.Utils private static string[] DetermineInferredScriptExtensions() { - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { return new string[] { "", ".cmd" }; } diff --git a/src/Microsoft.DotNet.InternalAbstractions/ApplicationEnvironment.cs b/src/Microsoft.DotNet.InternalAbstractions/ApplicationEnvironment.cs new file mode 100644 index 000000000..5cd986a9e --- /dev/null +++ b/src/Microsoft.DotNet.InternalAbstractions/ApplicationEnvironment.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.IO; + +namespace Microsoft.DotNet.InternalAbstractions +{ + public static class ApplicationEnvironment + { + public static string ApplicationBasePath { get; } = GetApplicationBasePath(); + + private static string GetApplicationBasePath() + { + var basePath = +#if NET451 + (string)AppDomain.CurrentDomain.GetData("APP_CONTEXT_BASE_DIRECTORY") ?? + AppDomain.CurrentDomain.BaseDirectory; +#else + AppContext.BaseDirectory; +#endif + return Path.GetFullPath(basePath); + } + } +} diff --git a/src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Darwin.cs b/src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Darwin.cs new file mode 100644 index 000000000..36e00d36e --- /dev/null +++ b/src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Darwin.cs @@ -0,0 +1,55 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.DotNet.InternalAbstractions.Native +{ + internal static partial class NativeMethods + { + public static class Darwin + { + private const int CTL_KERN = 1; + private const int KERN_OSRELEASE = 2; + + public unsafe static string GetKernelRelease() + { + const uint BUFFER_LENGTH = 32; + + var name = stackalloc int[2]; + name[0] = CTL_KERN; + name[1] = KERN_OSRELEASE; + + var buf = stackalloc byte[(int)BUFFER_LENGTH]; + var len = stackalloc uint[1]; + *len = BUFFER_LENGTH; + + try + { + // If the buffer isn't big enough, it seems sysctl still returns 0 and just sets len to the + // necessary buffer size. This appears to be contrary to the man page, but it's easy to detect + // by simply checking len against the buffer length. + if (sysctl(name, 2, buf, len, IntPtr.Zero, 0) == 0 && *len < BUFFER_LENGTH) + { + return Marshal.PtrToStringAnsi((IntPtr)buf, (int)*len); + } + } + catch (Exception ex) + { + throw new PlatformNotSupportedException("Error reading Darwin Kernel Version", ex); + } + throw new PlatformNotSupportedException("Unknown error reading Darwin Kernel Version"); + } + + [DllImport("libc")] + private unsafe static extern int sysctl( + int* name, + uint namelen, + byte* oldp, + uint* oldlenp, + IntPtr newp, + uint newlen); + } + } +} diff --git a/src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Unix.cs b/src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Unix.cs new file mode 100644 index 000000000..a4ab8376d --- /dev/null +++ b/src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Unix.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#if NET451 + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.DotNet.InternalAbstractions.Native +{ + internal static partial class NativeMethods + { + public static class Unix + { + public unsafe static string GetUname() + { + // Utsname shouldn't be larger than 2K + var buf = stackalloc byte[2048]; + + try + { + if (uname((IntPtr)buf) == 0) + { + return Marshal.PtrToStringAnsi((IntPtr)buf); + } + } + catch (Exception ex) + { + throw new PlatformNotSupportedException("Error reading Unix name", ex); + } + throw new PlatformNotSupportedException("Unknown error reading Unix name"); + } + + [DllImport("libc")] + private static extern int uname(IntPtr utsname); + } + } +} +#endif \ No newline at end of file diff --git a/src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Windows.cs b/src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Windows.cs new file mode 100644 index 000000000..bd51068b8 --- /dev/null +++ b/src/Microsoft.DotNet.InternalAbstractions/Native/NativeMethods.Windows.cs @@ -0,0 +1,43 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Runtime.InteropServices; + +namespace Microsoft.DotNet.InternalAbstractions.Native +{ + internal static partial class NativeMethods + { + public static class Windows + { + [StructLayout(LayoutKind.Sequential)] + internal struct RTL_OSVERSIONINFOEX + { + internal uint dwOSVersionInfoSize; + internal uint dwMajorVersion; + internal uint dwMinorVersion; + internal uint dwBuildNumber; + internal uint dwPlatformId; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] + internal string szCSDVersion; + } + + // This call avoids the shimming Windows does to report old versions + [DllImport("ntdll")] + private static extern int RtlGetVersion(out RTL_OSVERSIONINFOEX lpVersionInformation); + + internal static string RtlGetVersion() + { + RTL_OSVERSIONINFOEX osvi = new RTL_OSVERSIONINFOEX(); + osvi.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osvi); + if (RtlGetVersion(out osvi) == 0) + { + return $"{osvi.dwMajorVersion}.{osvi.dwMinorVersion}.{osvi.dwBuildNumber}"; + } + else + { + return null; + } + } + } + } +} diff --git a/src/Microsoft.DotNet.InternalAbstractions/Native/PlatformApis.cs b/src/Microsoft.DotNet.InternalAbstractions/Native/PlatformApis.cs new file mode 100644 index 000000000..1a46ef580 --- /dev/null +++ b/src/Microsoft.DotNet.InternalAbstractions/Native/PlatformApis.cs @@ -0,0 +1,171 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.IO; +using System.Runtime.InteropServices; + +namespace Microsoft.DotNet.InternalAbstractions.Native +{ + internal static class PlatformApis + { + private class DistroInfo + { + public string Id; + public string VersionId; + } + + private static readonly Lazy _platform = new Lazy(DetermineOSPlatform); + private static readonly Lazy _distroInfo = new Lazy(LoadDistroInfo); + + public static string GetOSName() + { + switch (GetOSPlatform()) + { + case Platform.Windows: + return "Windows"; + case Platform.Linux: + return GetDistroId() ?? "Linux"; + case Platform.Darwin: + return "Mac OS X"; + default: + return "Unknown"; + } + } + + public static string GetOSVersion() + { + switch (GetOSPlatform()) + { + case Platform.Windows: + return NativeMethods.Windows.RtlGetVersion() ?? string.Empty; + case Platform.Linux: + return GetDistroVersionId() ?? string.Empty; + case Platform.Darwin: + return GetDarwinVersion() ?? string.Empty; + default: + return string.Empty; + } + } + + private static string GetDarwinVersion() + { + Version version; + var kernelRelease = NativeMethods.Darwin.GetKernelRelease(); + if (!Version.TryParse(kernelRelease, out version) || version.Major < 5) + { + // 10.0 covers all versions prior to Darwin 5 + // Similarly, if the version is not a valid version number, but we have still detected that it is Darwin, we just assume + // it is OS X 10.0 + return "10.0"; + } + else + { + // Mac OS X 10.1 mapped to Darwin 5.x, and the mapping continues that way + // So just subtract 4 from the Darwin version. + // https://en.wikipedia.org/wiki/Darwin_%28operating_system%29 + return $"10.{version.Major - 4}"; + } + } + + public static Platform GetOSPlatform() + { + return _platform.Value; + } + + private static string GetDistroId() + { + return _distroInfo.Value?.Id; + } + + private static string GetDistroVersionId() + { + return _distroInfo.Value?.VersionId; + } + + private static DistroInfo LoadDistroInfo() + { + // Sample os-release file: + // NAME="Ubuntu" + // VERSION = "14.04.3 LTS, Trusty Tahr" + // ID = ubuntu + // ID_LIKE = debian + // PRETTY_NAME = "Ubuntu 14.04.3 LTS" + // VERSION_ID = "14.04" + // HOME_URL = "http://www.ubuntu.com/" + // SUPPORT_URL = "http://help.ubuntu.com/" + // BUG_REPORT_URL = "http://bugs.launchpad.net/ubuntu/" + // We use ID and VERSION_ID + + if (File.Exists("/etc/os-release")) + { + var lines = File.ReadAllLines("/etc/os-release"); + var result = new DistroInfo(); + foreach (var line in lines) + { + if (line.StartsWith("ID=", StringComparison.Ordinal)) + { + result.Id = line.Substring(3).Trim('"', '\''); + } + else if (line.StartsWith("VERSION_ID=", StringComparison.Ordinal)) + { + result.VersionId = line.Substring(11).Trim('"', '\''); + } + } + return result; + } + return null; + } + + // I could probably have just done one method signature and put the #if inside the body but the implementations + // are just completely different so I wanted to make that clear by putting the whole thing inside the #if. +#if NET451 + private static Platform DetermineOSPlatform() + { + var platform = (int)Environment.OSVersion.Platform; + var isWindows = (platform != 4) && (platform != 6) && (platform != 128); + + if (isWindows) + { + return Platform.Windows; + } + else + { + try + { + var uname = NativeMethods.Unix.GetUname(); + if (string.Equals(uname, "Darwin", StringComparison.OrdinalIgnoreCase)) + { + return Platform.Darwin; + } + if (string.Equals(uname, "Linux", StringComparison.OrdinalIgnoreCase)) + { + return Platform.Linux; + } + } + catch + { + } + return Platform.Unknown; + } + } +#else + private static Platform DetermineOSPlatform() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return Platform.Windows; + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return Platform.Linux; + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return Platform.Darwin; + } + return Platform.Unknown; + } +#endif + } +} diff --git a/src/Microsoft.DotNet.InternalAbstractions/Platform.cs b/src/Microsoft.DotNet.InternalAbstractions/Platform.cs new file mode 100644 index 000000000..c289a834c --- /dev/null +++ b/src/Microsoft.DotNet.InternalAbstractions/Platform.cs @@ -0,0 +1,13 @@ +// Copyright(c) .NET Foundation and contributors.All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.DotNet.InternalAbstractions +{ + public enum Platform + { + Unknown = 0, + Windows = 1, + Linux = 2, + Darwin = 3 + } +} diff --git a/src/Microsoft.DotNet.InternalAbstractions/RuntimeEnvironment.cs b/src/Microsoft.DotNet.InternalAbstractions/RuntimeEnvironment.cs new file mode 100644 index 000000000..1e754ee1e --- /dev/null +++ b/src/Microsoft.DotNet.InternalAbstractions/RuntimeEnvironment.cs @@ -0,0 +1,104 @@ +// Copyright(c) .NET Foundation and contributors.All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.DotNet.InternalAbstractions.Native; + +namespace Microsoft.DotNet.InternalAbstractions +{ + public static class RuntimeEnvironment + { + private static readonly string OverrideEnvironmentVariableName = "DOTNET_RUNTIME_ID"; + + public static Platform OperatingSystemPlatform { get; } = PlatformApis.GetOSPlatform(); + + public static string OperatingSystemVersion { get; } = PlatformApis.GetOSVersion(); + + public static string OperatingSystem { get; } = PlatformApis.GetOSName(); + + public static string RuntimeArchitecture { get; } = GetArch(); + + private static string GetArch() + { +#if NET451 + return Environment.Is64BitProcess ? "x64" : "x86"; +#else + return IntPtr.Size == 8 ? "x64" : "x86"; +#endif + } + + public static string GetRuntimeIdentifier() + { + return + Environment.GetEnvironmentVariable(OverrideEnvironmentVariableName) ?? + (GetRIDOS() + GetRIDVersion() + GetRIDArch()); + } + + private static string GetRIDArch() + { + if (!string.IsNullOrEmpty(RuntimeArchitecture)) + { + return $"-{RuntimeArchitecture.ToLowerInvariant()}"; + } + return string.Empty; + } + + private static string GetRIDVersion() + { + // Windows RIDs do not separate OS name and version by "." due to legacy + // Others do, that's why we have the "." prefix on them below + switch (OperatingSystemPlatform) + { + case Platform.Windows: + return GetWindowsProductVersion(); + case Platform.Linux: + return $".{OperatingSystemVersion}"; + case Platform.Darwin: + return $".{OperatingSystemVersion}"; + default: + return string.Empty; // Unknown Platform? Unknown Version! + } + } + + private static string GetWindowsProductVersion() + { + var ver = Version.Parse(OperatingSystemVersion); + if (ver.Major == 6) + { + if (ver.Minor == 1) + { + return "7"; + } + else if (ver.Minor == 2) + { + return "8"; + } + else if (ver.Minor == 3) + { + return "81"; + } + } + else if (ver.Major == 10 && ver.Minor == 0) + { + // Not sure if there will be 10.x (where x > 0) or even 11, so let's be defensive. + return "10"; + } + return string.Empty; // Unknown version + } + + private static string GetRIDOS() + { + switch (OperatingSystemPlatform) + { + case Platform.Windows: + return "win"; + case Platform.Linux: + return OperatingSystem.ToLowerInvariant(); + case Platform.Darwin: + return "osx"; + default: + return "unknown"; + } + } + } +} diff --git a/src/Microsoft.DotNet.InternalAbstractions/project.json b/src/Microsoft.DotNet.InternalAbstractions/project.json index 319f32dbb..d140d3edb 100644 --- a/src/Microsoft.DotNet.InternalAbstractions/project.json +++ b/src/Microsoft.DotNet.InternalAbstractions/project.json @@ -7,14 +7,23 @@ }, "compilationOptions": { "warningsAsErrors": true, - "keyFile": "../../tools/Key.snk" - }, - "dependencies": { - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-20581" + "keyFile": "../../tools/Key.snk", + "allowUnsafe": true }, "frameworks": { - "net451": {}, - "netstandard1.3": {} + "net451": { }, + "netstandard1.3": { + "dependencies": { + "System.AppContext": "4.1.0-rc2-24027", + "System.Collections": "4.0.11-rc2-24027", + "System.IO": "4.1.0-rc2-24027", + "System.IO.FileSystem": "4.0.1-rc2-24027", + "System.Reflection.TypeExtensions": "4.1.0-rc2-24027", + "System.Runtime.Extensions": "4.1.0-rc2-24027", + "System.Runtime.InteropServices": "4.1.0-rc2-24027", + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0-rc2-24027" + } + } }, - "scripts": {} + "scripts": { } } diff --git a/src/Microsoft.DotNet.ProjectModel.Workspaces/ProjectJsonWorkspace.cs b/src/Microsoft.DotNet.ProjectModel.Workspaces/ProjectJsonWorkspace.cs index d49dbf80c..c37b3967b 100644 --- a/src/Microsoft.DotNet.ProjectModel.Workspaces/ProjectJsonWorkspace.cs +++ b/src/Microsoft.DotNet.ProjectModel.Workspaces/ProjectJsonWorkspace.cs @@ -12,9 +12,9 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Text; using Microsoft.DotNet.Cli.Compiler.Common; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.DotNet.ProjectModel.Files; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; namespace Microsoft.DotNet.ProjectModel.Workspaces @@ -225,7 +225,7 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces { keyFile = Path.GetFullPath(Path.Combine(projectDirectory, compilerOptions.KeyFile)); - if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Extensions.PlatformAbstractions.Platform.Windows || useOssSigning) + if (RuntimeEnvironment.OperatingSystemPlatform != InternalAbstractions.Platform.Windows || useOssSigning) { return options.WithCryptoPublicKey( SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile))); diff --git a/src/Microsoft.DotNet.ProjectModel/FileNameSuffixes.cs b/src/Microsoft.DotNet.ProjectModel/FileNameSuffixes.cs index 404a25744..a8559daee 100644 --- a/src/Microsoft.DotNet.ProjectModel/FileNameSuffixes.cs +++ b/src/Microsoft.DotNet.ProjectModel/FileNameSuffixes.cs @@ -1,5 +1,5 @@ using System; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.ProjectModel { @@ -13,7 +13,7 @@ namespace Microsoft.DotNet.ProjectModel { get { - switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) + switch (RuntimeEnvironment.OperatingSystemPlatform) { case Platform.Windows: return Windows; diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs index 787cd3556..39a8f355e 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs @@ -6,10 +6,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Resolution; using Microsoft.Extensions.Internal; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; namespace Microsoft.DotNet.ProjectModel @@ -267,7 +267,7 @@ namespace Microsoft.DotNet.ProjectModel { // we got a ridless target for desktop so turning portable mode on isPortable = true; - var legacyRuntime = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + var legacyRuntime = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); if (RuntimeIdentifiers.Contains(legacyRuntime)) { runtime = legacyRuntime; diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/FrameworkReferenceResolver.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/FrameworkReferenceResolver.cs index f522a000e..985dbdd03 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/FrameworkReferenceResolver.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/FrameworkReferenceResolver.cs @@ -7,11 +7,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Versioning; -using System.Threading.Tasks; using System.Xml.Linq; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel.Utilities; using Microsoft.Extensions.DependencyModel.Resolution; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; namespace Microsoft.DotNet.ProjectModel.Resolution @@ -63,7 +62,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution return referenceAssembliesPath; } - if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) { // There is no reference assemblies path outside of windows // The environment variable can be used to specify one @@ -210,7 +209,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution private static FrameworkInformation GetFrameworkInformation(NuGetFramework targetFramework, string referenceAssembliesPath) { // Check for legacy frameworks - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows && + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows && targetFramework.IsDesktop() && targetFramework.Version <= new Version(3, 5, 0, 0)) { diff --git a/src/Microsoft.DotNet.ProjectModel/RuntimeEnvironmentRidExtensions.cs b/src/Microsoft.DotNet.ProjectModel/RuntimeEnvironmentRidExtensions.cs index 20ed4227d..f5d439157 100644 --- a/src/Microsoft.DotNet.ProjectModel/RuntimeEnvironmentRidExtensions.cs +++ b/src/Microsoft.DotNet.ProjectModel/RuntimeEnvironmentRidExtensions.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.Extensions.PlatformAbstractions +namespace Microsoft.DotNet.InternalAbstractions { // This is to support some legacy stuff. // dnu restore (and thus dotnet restore) always uses win7-x64 as the Windows restore target, @@ -12,11 +12,11 @@ namespace Microsoft.Extensions.PlatformAbstractions public static class RuntimeEnvironmentRidExtensions { // Work around NuGet/Home#1941 - public static IEnumerable GetOverrideRestoreRuntimeIdentifiers(this IRuntimeEnvironment env) + public static IEnumerable GetOverrideRestoreRuntimeIdentifiers() { - if (env.OperatingSystemPlatform != Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) { - yield return env.GetRuntimeIdentifier(); + yield return RuntimeEnvironment.GetRuntimeIdentifier(); } else { @@ -26,44 +26,44 @@ namespace Microsoft.Extensions.PlatformAbstractions } // Gets the identfier that is used for restore by default (this is different from the actual RID, but only on Windows) - public static string GetLegacyRestoreRuntimeIdentifier(this IRuntimeEnvironment env) + public static string GetLegacyRestoreRuntimeIdentifier() { - if (env.OperatingSystemPlatform != Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) { - return env.GetRuntimeIdentifier(); + return RuntimeEnvironment.GetRuntimeIdentifier(); } else { - var arch = env.RuntimeArchitecture.ToLowerInvariant(); + var arch = RuntimeEnvironment.RuntimeArchitecture.ToLowerInvariant(); return "win7-" + arch; } } - public static IEnumerable GetAllCandidateRuntimeIdentifiers(this IRuntimeEnvironment env) + public static IEnumerable GetAllCandidateRuntimeIdentifiers() { - if (env.OperatingSystemPlatform != Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) { - yield return env.GetRuntimeIdentifier(); + yield return RuntimeEnvironment.GetRuntimeIdentifier(); } else { - var arch = env.RuntimeArchitecture.ToLowerInvariant(); - if (env.OperatingSystemVersion.StartsWith("6.1", StringComparison.Ordinal)) + var arch = RuntimeEnvironment.RuntimeArchitecture.ToLowerInvariant(); + if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("6.1", StringComparison.Ordinal)) { yield return "win7-" + arch; } - else if (env.OperatingSystemVersion.StartsWith("6.2", StringComparison.Ordinal)) + else if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("6.2", StringComparison.Ordinal)) { yield return "win8-" + arch; yield return "win7-" + arch; } - else if (env.OperatingSystemVersion.StartsWith("6.3", StringComparison.Ordinal)) + else if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("6.3", StringComparison.Ordinal)) { yield return "win81-" + arch; yield return "win8-" + arch; yield return "win7-" + arch; } - else if (env.OperatingSystemVersion.StartsWith("10.0", StringComparison.Ordinal)) + else if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("10.0", StringComparison.Ordinal)) { yield return "win10-" + arch; yield return "win81-" + arch; diff --git a/src/Microsoft.DotNet.ProjectModel/Utilities/PathUtility.cs b/src/Microsoft.DotNet.ProjectModel/Utilities/PathUtility.cs index 2381ea32b..d5ea5d44a 100644 --- a/src/Microsoft.DotNet.ProjectModel/Utilities/PathUtility.cs +++ b/src/Microsoft.DotNet.ProjectModel/Utilities/PathUtility.cs @@ -3,7 +3,7 @@ using System; using System.IO; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.ProjectModel.Utilities { @@ -84,7 +84,7 @@ namespace Microsoft.DotNet.ProjectModel.Utilities } StringComparison compare; - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { compare = StringComparison.OrdinalIgnoreCase; // check if paths are on the same volume diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs index 2ba03fcc3..353f59332 100644 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs +++ b/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs @@ -2,11 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.IO; -using System.Reflection; using System.Collections.Generic; using System.Linq; -using Microsoft.Extensions.PlatformAbstractions; +using System.Reflection; namespace Microsoft.Extensions.DependencyModel { diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs index 858bc3316..77652c240 100644 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs +++ b/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using Microsoft.Extensions.PlatformAbstractions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/AppBaseCompilationAssemblyResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/AppBaseCompilationAssemblyResolver.cs index 9c047365f..2f956f666 100644 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/AppBaseCompilationAssemblyResolver.cs +++ b/src/Microsoft.Extensions.DependencyModel/Resolution/AppBaseCompilationAssemblyResolver.cs @@ -4,8 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Reflection; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.Extensions.EnvironmentAbstractions; namespace Microsoft.Extensions.DependencyModel.Resolution @@ -25,7 +24,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution } internal AppBaseCompilationAssemblyResolver(IFileSystem fileSystem) - : this(fileSystem, PlatformServices.Default.Application.ApplicationBasePath) + : this(fileSystem, ApplicationEnvironment.ApplicationBasePath) { } diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/DotNetReferenceAssembliesPathResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/DotNetReferenceAssembliesPathResolver.cs index ff214d8a7..ef356d054 100644 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/DotNetReferenceAssembliesPathResolver.cs +++ b/src/Microsoft.Extensions.DependencyModel/Resolution/DotNetReferenceAssembliesPathResolver.cs @@ -1,10 +1,8 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.IO; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.Extensions.EnvironmentAbstractions; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.Extensions.DependencyModel.Resolution { @@ -12,7 +10,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution { public static readonly string DotNetReferenceAssembliesPathEnv = "DOTNET_REFERENCE_ASSEMBLIES_PATH"; - internal static string Resolve(IEnvironment envirnment, IFileSystem fileSystem, IRuntimeEnvironment runtimeEnvironment) + internal static string Resolve(IEnvironment envirnment, IFileSystem fileSystem) { var path = envirnment.GetEnvironmentVariable(DotNetReferenceAssembliesPathEnv); if (!string.IsNullOrEmpty(path)) @@ -20,17 +18,17 @@ namespace Microsoft.Extensions.DependencyModel.Resolution return path; } - return GetDefaultDotNetReferenceAssembliesPath(fileSystem, runtimeEnvironment); + return GetDefaultDotNetReferenceAssembliesPath(fileSystem); } public static string Resolve() { - return Resolve(EnvironmentWrapper.Default, FileSystemWrapper.Default, PlatformServices.Default.Runtime); + return Resolve(EnvironmentWrapper.Default, FileSystemWrapper.Default); } - private static string GetDefaultDotNetReferenceAssembliesPath(IFileSystem fileSystem, IRuntimeEnvironment runtimeEnvironment) + private static string GetDefaultDotNetReferenceAssembliesPath(IFileSystem fileSystem) { - var os = runtimeEnvironment.OperatingSystemPlatform; + var os = RuntimeEnvironment.OperatingSystemPlatform; if (os == Platform.Windows) { diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCompilationAssemblyResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCompilationAssemblyResolver.cs index 680d24e99..f49f7815d 100644 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCompilationAssemblyResolver.cs +++ b/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCompilationAssemblyResolver.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.Extensions.EnvironmentAbstractions; namespace Microsoft.Extensions.DependencyModel.Resolution @@ -15,7 +15,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution private readonly string _nugetPackageDirectory; public PackageCompilationAssemblyResolver() - : this(EnvironmentWrapper.Default, PlatformServices.Default.Runtime, FileSystemWrapper.Default) + : this(EnvironmentWrapper.Default, FileSystemWrapper.Default) { } @@ -25,9 +25,8 @@ namespace Microsoft.Extensions.DependencyModel.Resolution } internal PackageCompilationAssemblyResolver(IEnvironment environment, - IRuntimeEnvironment runtimeEnvironment, IFileSystem fileSystem) - : this(fileSystem, GetDefaultPackageDirectory(runtimeEnvironment, environment)) + : this(fileSystem, GetDefaultPackageDirectory(environment)) { } @@ -37,7 +36,10 @@ namespace Microsoft.Extensions.DependencyModel.Resolution _nugetPackageDirectory = nugetPackageDirectory; } - internal static string GetDefaultPackageDirectory(IRuntimeEnvironment runtimeEnvironment, IEnvironment environment) + private static string GetDefaultPackageDirectory(IEnvironment environment) => + GetDefaultPackageDirectory(RuntimeEnvironment.OperatingSystemPlatform, environment); + + internal static string GetDefaultPackageDirectory(Platform osPlatform, IEnvironment environment) { var packageDirectory = environment.GetEnvironmentVariable("NUGET_PACKAGES"); @@ -47,7 +49,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution } string basePath; - if (runtimeEnvironment.OperatingSystemPlatform == Platform.Windows) + if (osPlatform == Platform.Windows) { basePath = environment.GetEnvironmentVariable("USERPROFILE"); } diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs index 55f212660..9ad6b3d41 100644 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs +++ b/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.Extensions.EnvironmentAbstractions; namespace Microsoft.Extensions.DependencyModel.Resolution @@ -16,7 +16,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution private readonly string[] _fallbackSearchPaths; public ReferenceAssemblyPathResolver() - : this(FileSystemWrapper.Default, PlatformServices.Default.Runtime, EnvironmentWrapper.Default) + : this(FileSystemWrapper.Default, EnvironmentWrapper.Default) { } @@ -25,10 +25,10 @@ namespace Microsoft.Extensions.DependencyModel.Resolution { } - internal ReferenceAssemblyPathResolver(IFileSystem fileSystem, IRuntimeEnvironment runtimeEnvironment, IEnvironment environment) + internal ReferenceAssemblyPathResolver(IFileSystem fileSystem, IEnvironment environment) : this(fileSystem, - GetDefaultReferenceAssembliesPath(runtimeEnvironment, fileSystem, environment), - GetFallbackSearchPaths(fileSystem, runtimeEnvironment, environment)) + GetDefaultReferenceAssembliesPath(fileSystem, RuntimeEnvironment.OperatingSystemPlatform, environment), + GetFallbackSearchPaths(fileSystem, RuntimeEnvironment.OperatingSystemPlatform, environment)) { } @@ -85,9 +85,9 @@ namespace Microsoft.Extensions.DependencyModel.Resolution return false; } - internal static string[] GetFallbackSearchPaths(IFileSystem fileSystem, IRuntimeEnvironment runtimeEnvironment, IEnvironment environment) + internal static string[] GetFallbackSearchPaths(IFileSystem fileSystem, Platform platform, IEnvironment environment) { - if (runtimeEnvironment.OperatingSystemPlatform != Platform.Windows) + if (platform != Platform.Windows) { return new string[0]; } @@ -101,16 +101,16 @@ namespace Microsoft.Extensions.DependencyModel.Resolution return new[] { net20Dir }; } - internal static string GetDefaultReferenceAssembliesPath(IRuntimeEnvironment runtimeEnvironment, IFileSystem fileSystem, IEnvironment environment) + internal static string GetDefaultReferenceAssembliesPath(IFileSystem fileSystem, Platform platform, IEnvironment environment) { // Allow setting the reference assemblies path via an environment variable - var referenceAssembliesPath = DotNetReferenceAssembliesPathResolver.Resolve(environment, fileSystem, runtimeEnvironment); + var referenceAssembliesPath = DotNetReferenceAssembliesPathResolver.Resolve(environment, fileSystem); if (!string.IsNullOrEmpty(referenceAssembliesPath)) { return referenceAssembliesPath; } - if (runtimeEnvironment.OperatingSystemPlatform != Platform.Windows) + if (platform != Platform.Windows) { // There is no reference assemblies path outside of windows // The environment variable can be used to specify one diff --git a/src/Microsoft.Extensions.DependencyModel/project.json b/src/Microsoft.Extensions.DependencyModel/project.json index 307286bf1..e3fac5e61 100644 --- a/src/Microsoft.Extensions.DependencyModel/project.json +++ b/src/Microsoft.Extensions.DependencyModel/project.json @@ -26,7 +26,8 @@ "imports": "portable-net45+wp80+win8+wpa81+dnxcore50", "dependencies": { "System.Diagnostics.Debug": "4.0.11-rc2-24027", - "System.Dynamic.Runtime": "4.0.11-rc2-24027" + "System.Dynamic.Runtime": "4.0.11-rc2-24027", + "System.Linq": "4.1.0-rc2-24027" } } }, diff --git a/src/Microsoft.Extensions.Testing.Abstractions/project.json b/src/Microsoft.Extensions.Testing.Abstractions/project.json index 879f178ee..e31af199f 100644 --- a/src/Microsoft.Extensions.Testing.Abstractions/project.json +++ b/src/Microsoft.Extensions.Testing.Abstractions/project.json @@ -14,6 +14,7 @@ "Newtonsoft.Json": "7.0.1", "Microsoft.DotNet.ProjectModel": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc2-20581", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-20581", "Microsoft.DiaSymReader": "1.0.6", "Microsoft.DiaSymReader.Native": "1.3.3" }, diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 11d9970e1..45bba2ddb 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using System.Text; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel.Server; using Microsoft.DotNet.Tools.Build; using Microsoft.DotNet.Tools.Compiler; @@ -17,7 +18,6 @@ using Microsoft.DotNet.Tools.Publish; using Microsoft.DotNet.Tools.Restore; using Microsoft.DotNet.Tools.Run; using Microsoft.DotNet.Tools.Test; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; namespace Microsoft.DotNet.Cli @@ -186,12 +186,11 @@ namespace Microsoft.DotNet.Cli Reporter.Output.WriteLine($" Version: {Product.Version}"); Reporter.Output.WriteLine($" Commit Sha: {commitSha}"); Reporter.Output.WriteLine(); - var runtimeEnvironment = PlatformServices.Default.Runtime; Reporter.Output.WriteLine("Runtime Environment:"); - Reporter.Output.WriteLine($" OS Name: {runtimeEnvironment.OperatingSystem}"); - Reporter.Output.WriteLine($" OS Version: {runtimeEnvironment.OperatingSystemVersion}"); - Reporter.Output.WriteLine($" OS Platform: {runtimeEnvironment.OperatingSystemPlatform}"); - Reporter.Output.WriteLine($" RID: {runtimeEnvironment.GetRuntimeIdentifier()}"); + Reporter.Output.WriteLine($" OS Name: {RuntimeEnvironment.OperatingSystem}"); + Reporter.Output.WriteLine($" OS Version: {RuntimeEnvironment.OperatingSystemVersion}"); + Reporter.Output.WriteLine($" OS Platform: {RuntimeEnvironment.OperatingSystemPlatform}"); + Reporter.Output.WriteLine($" RID: {RuntimeEnvironment.GetRuntimeIdentifier()}"); } private static bool IsArg(string candidate, string longName) diff --git a/src/dotnet/Telemetry.cs b/src/dotnet/Telemetry.cs index f5470907b..447322a51 100644 --- a/src/dotnet/Telemetry.cs +++ b/src/dotnet/Telemetry.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using Microsoft.ApplicationInsights; using Microsoft.DotNet.Cli.Utils; -using Microsoft.Extensions.PlatformAbstractions; -using System.Diagnostics; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Cli { @@ -41,13 +41,13 @@ namespace Microsoft.DotNet.Cli _client.InstrumentationKey = InstrumentationKey; _client.Context.Session.Id = Guid.NewGuid().ToString(); - var runtimeEnvironment = PlatformServices.Default.Runtime; - _client.Context.Device.OperatingSystem = runtimeEnvironment.OperatingSystem; + + _client.Context.Device.OperatingSystem = RuntimeEnvironment.OperatingSystem; _commonProperties = new Dictionary(); - _commonProperties.Add(OSVersion, runtimeEnvironment.OperatingSystemVersion); - _commonProperties.Add(OSPlatform, runtimeEnvironment.OperatingSystemPlatform.ToString()); - _commonProperties.Add(RuntimeId, runtimeEnvironment.GetRuntimeIdentifier()); + _commonProperties.Add(OSVersion, RuntimeEnvironment.OperatingSystemVersion); + _commonProperties.Add(OSPlatform, RuntimeEnvironment.OperatingSystemPlatform.ToString()); + _commonProperties.Add(RuntimeId, RuntimeEnvironment.GetRuntimeIdentifier()); _commonProperties.Add(ProductVersion, Product.Version); _commonMeasurements = new Dictionary(); } diff --git a/src/dotnet/commands/dotnet-build/BuildCommandApp.cs b/src/dotnet/commands/dotnet-build/BuildCommandApp.cs index ce1b0626f..758ce8420 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandApp.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandApp.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; // This class is responsible with defining the arguments for the Compile verb. @@ -121,7 +121,7 @@ namespace Microsoft.DotNet.Tools.Compiler IEnumerable frameworks = null; if (_frameworkOption.HasValue()) { - frameworks = new [] { NuGetFramework.Parse(_frameworkOption.Value()) }; + frameworks = new[] { NuGetFramework.Parse(_frameworkOption.Value()) }; } var success = execute(files, frameworks, this); @@ -136,7 +136,7 @@ namespace Microsoft.DotNet.Tools.Compiler var rids = new List(); if (string.IsNullOrEmpty(RuntimeValue)) { - return PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers(); + return RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers(); } else { diff --git a/src/dotnet/commands/dotnet-build/DotnetProjectBuilder.cs b/src/dotnet/commands/dotnet-build/DotnetProjectBuilder.cs index 7b27d2a92..76d155c94 100644 --- a/src/dotnet/commands/dotnet-build/DotnetProjectBuilder.cs +++ b/src/dotnet/commands/dotnet-build/DotnetProjectBuilder.cs @@ -2,15 +2,12 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Compiler; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Build { @@ -23,7 +20,7 @@ namespace Microsoft.DotNet.Tools.Build private readonly DotNetCommandFactory _commandFactory; private readonly IncrementalManager _incrementalManager; - public DotNetProjectBuilder(BuildCommandApp args): base(args.ShouldSkipDependencies) + public DotNetProjectBuilder(BuildCommandApp args) : base(args.ShouldSkipDependencies) { _args = args; diff --git a/src/dotnet/commands/dotnet-build/IncrementalManager.cs b/src/dotnet/commands/dotnet-build/IncrementalManager.cs index c367079a6..3f2bec256 100644 --- a/src/dotnet/commands/dotnet-build/IncrementalManager.cs +++ b/src/dotnet/commands/dotnet-build/IncrementalManager.cs @@ -7,12 +7,7 @@ using System.IO; using System.Linq; using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Utilities; using Microsoft.DotNet.Tools.Compiler; -using Microsoft.Extensions.PlatformAbstractions; -using Microsoft.DotNet.ProjectModel.Compilation; -using NuGet.Protocol.Core.Types; namespace Microsoft.DotNet.Tools.Build { diff --git a/src/dotnet/commands/dotnet-publish/PublishCommand.cs b/src/dotnet/commands/dotnet-publish/PublishCommand.cs index e89abb1bc..5b0fe4711 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommand.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommand.cs @@ -8,13 +8,13 @@ using System.Linq; using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Files; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.DotNet.ProjectModel.Files; using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Utilities; using Microsoft.DotNet.Tools.Common; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; namespace Microsoft.DotNet.Tools.Publish @@ -150,10 +150,10 @@ namespace Microsoft.DotNet.Tools.Publish var runtimeAssetsToCopy = export.RuntimeAssets.Where(a => ShouldCopyExportRuntimeAsset(context, buildOutputPaths, export, a)); runtimeAssetsToCopy.StructuredCopyTo(outputPath, outputPaths.IntermediateOutputDirectoryPath); - foreach(var resourceAsset in export.ResourceAssemblies) + foreach (var resourceAsset in export.ResourceAssemblies) { var dir = Path.Combine(outputPath, resourceAsset.Locale); - if(!Directory.Exists(dir)) + if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } @@ -291,7 +291,7 @@ namespace Microsoft.DotNet.Tools.Publish foreach (var dependency in dependencies) { var export = exports[dependency.Name]; - if(export.Library.Identity.Version.Equals(dependency.VersionRange.MinVersion)) + if (export.Library.Identity.Version.Equals(dependency.VersionRange.MinVersion)) { exclusionList.Add(export.Library.Identity.Name); CollectDependencies(exports, export.Library.Dependencies, exclusionList); @@ -454,7 +454,7 @@ namespace Microsoft.DotNet.Tools.Publish contexts.Where(c => Equals(c.TargetFramework, framework)); var rids = string.IsNullOrEmpty(runtime) ? - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers() : + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers() : new[] { runtime }; return contexts.Select(c => Workspace.GetRuntimeContext(c, rids)); diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index a9b3a99dc..6616f75dc 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -5,13 +5,13 @@ using System; using System.Linq; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; namespace Microsoft.DotNet.Tools.Restore { public partial class RestoreCommand { - private static readonly string DefaultRid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + private static readonly string DefaultRid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); public static int Run(string[] args) { @@ -28,7 +28,7 @@ namespace Microsoft.DotNet.Tools.Restore // "--verbosity" switch that goes BEFORE the command var quiet = args.Any(s => s.Equals("--quiet", StringComparison.OrdinalIgnoreCase)); args = args.Where(s => !s.Equals("--quiet", StringComparison.OrdinalIgnoreCase)).ToArray(); - + app.OnExecute(() => { try diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index 8f6ed9e19..c323ea85a 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -7,8 +7,8 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; -using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; namespace Microsoft.DotNet.Tools.Run @@ -70,7 +70,7 @@ namespace Microsoft.DotNet.Tools.Run var frameworkContexts = _workspace.GetProjectContextCollection(Project).FrameworkOnlyContexts; - var rids = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers(); + var rids = RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers(); ProjectContext frameworkContext; if (Framework == null) diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index f89d17a33..9a0204abe 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -6,8 +6,8 @@ using System.Diagnostics; using System.IO; using System.Linq; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Test { @@ -44,7 +44,7 @@ namespace Microsoft.DotNet.Tools.Test var projectPath = GetProjectPath(dotnetTestParams.ProjectPath); var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime) ? new[] { dotnetTestParams.Runtime } : - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers(); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers(); var exitCode = 0; // Create a workspace diff --git a/test/ArgumentForwardingTests/ArgumentForwardingTests.cs b/test/ArgumentForwardingTests/ArgumentForwardingTests.cs index ed08e45bf..31b7d775c 100644 --- a/test/ArgumentForwardingTests/ArgumentForwardingTests.cs +++ b/test/ArgumentForwardingTests/ArgumentForwardingTests.cs @@ -11,7 +11,6 @@ using Xunit; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; using System.Diagnostics; using FluentAssertions; diff --git a/test/EndToEnd/EndToEndTest.cs b/test/EndToEnd/EndToEndTest.cs index 407016c69..eeb4e6ace 100644 --- a/test/EndToEnd/EndToEndTest.cs +++ b/test/EndToEnd/EndToEndTest.cs @@ -5,10 +5,9 @@ using System; using System.IO; using System.Linq; using System.Runtime.InteropServices; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; using Xunit; -using System.Diagnostics; namespace Microsoft.DotNet.Tests.EndToEnd { @@ -152,7 +151,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd .Should() .Pass(); } - + [Fact] public void TestDotnetPack() { @@ -169,7 +168,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd var publishCommand = new PublishCommand(TestProject, output: OutputDirectory); publishCommand.Execute().Should().Pass(); - TestExecutable(OutputDirectory, publishCommand.GetPortableOutputName(), s_expectedOutput); + TestExecutable(OutputDirectory, publishCommand.GetPortableOutputName(), s_expectedOutput); } [Fact] @@ -196,7 +195,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd TestProject = Path.Combine(TestDirectory, "project.json"); OutputDirectory = Path.Combine(TestDirectory, s_outputdirName); - Rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + Rid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); } private static void SetupStaticTestProject() @@ -208,7 +207,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd { Directory.Delete(RestoredTestProjectDirectory, true); } - catch(Exception) {} + catch (Exception) { } Directory.CreateDirectory(RestoredTestProjectDirectory); @@ -227,7 +226,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd private bool IsNativeCompilationSupported() { bool isSupported = true; - var platform = PlatformServices.Default.Runtime.OperatingSystem.ToLower(); + var platform = RuntimeEnvironment.OperatingSystem.ToLower(); switch (platform) { case "centos": diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenACompositeCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenACompositeCommandResolver.cs index 988d9e319..1e9e9129c 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenACompositeCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenACompositeCommandResolver.cs @@ -1,21 +1,11 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; using System.Collections.Generic; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Linq; -using Xunit; -using Moq; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Threading; using FluentAssertions; -using NuGet.Frameworks; +using Microsoft.DotNet.Tools.Test.Utilities; +using Moq; +using Xunit; namespace Microsoft.DotNet.Cli.Utils.Tests { diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs index 23cc2c4fc..3a92bad95 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenADefaultCommandResolver.cs @@ -1,21 +1,10 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; using System.Linq; -using Xunit; -using Moq; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Threading; using FluentAssertions; -using NuGet.Frameworks; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; namespace Microsoft.DotNet.Cli.Utils.Tests { diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAPathCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAPathCommandResolver.cs deleted file mode 100644 index 4004c5b00..000000000 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAPathCommandResolver.cs +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Linq; -using Xunit; -using Moq; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Threading; -using FluentAssertions; -using NuGet.Frameworks; - -namespace Microsoft.DotNet.Cli.Utils.Tests -{ - public class GivenAPathCommandResolver - { - private static readonly string s_testDirectory = Path.Combine(AppContext.BaseDirectory, "pathTestDirectory"); - - [Fact] - public void It_returns_null_when_CommandName_is_null() - { - var pathCommandResolver = SetupPlatformPathCommandResolver(); - - var commandResolverArguments = new CommandResolverArguments() - { - CommandName = null, - CommandArguments = null - }; - - var result = pathCommandResolver.Resolve(commandResolverArguments); - - result.Should().BeNull(); - } - - [Fact] - public void It_returns_null_when_CommandName_does_not_exist_in_PATH() - { - var emptyPathEnvironmentMock = new Mock(); - emptyPathEnvironmentMock.Setup(e => e - .GetCommandPath(It.IsAny(), It.IsAny())) - .Returns((string)null); - - var pathCommandResolver = SetupPlatformPathCommandResolver(emptyPathEnvironmentMock.Object); - - var commandResolverArguments = new CommandResolverArguments() - { - CommandName = "nonexistent-command", - CommandArguments = null - }; - - var result = pathCommandResolver.Resolve(commandResolverArguments); - - result.Should().BeNull(); - } - - [Fact] - public void It_returns_a_CommandSpec_with_CommandName_as_FileName_when_CommandName_exists_in_PATH() - { - var testCommandPath = CommandResolverTestUtils.CreateNonRunnableTestCommand( - s_testDirectory, - "pathtestcommand1", - ".exe"); - - var staticPathEnvironmentMock = new Mock(); - staticPathEnvironmentMock.Setup(e => e - .GetCommandPath(It.IsAny(), It.IsAny())) - .Returns(testCommandPath); - - var pathCommandResolver = SetupPlatformPathCommandResolver(staticPathEnvironmentMock.Object, forceGeneric: true); - - var commandResolverArguments = new CommandResolverArguments() - { - CommandName = Path.GetFileNameWithoutExtension(testCommandPath), - CommandArguments = null - }; - - var result = pathCommandResolver.Resolve(commandResolverArguments); - - result.Should().NotBeNull(); - - var commandFile = Path.GetFileNameWithoutExtension(result.Path); - - commandFile.Should().Be(Path.GetFileNameWithoutExtension(testCommandPath)); - } - - [Fact] - public void It_escapes_CommandArguments_when_returning_a_CommandSpec() - { - var testCommandPath = CommandResolverTestUtils.CreateNonRunnableTestCommand( - s_testDirectory, - "pathtestcommand1", - ".exe"); - - var staticPathEnvironmentMock = new Mock(); - staticPathEnvironmentMock.Setup(e => e - .GetCommandPath(It.IsAny(), It.IsAny())) - .Returns(testCommandPath); - - var pathCommandResolver = SetupPlatformPathCommandResolver(staticPathEnvironmentMock.Object, forceGeneric: true); - - var commandResolverArguments = new CommandResolverArguments() - { - CommandName = Path.GetFileNameWithoutExtension(testCommandPath), - CommandArguments = new [] {"arg with space"} - }; - - var result = pathCommandResolver.Resolve(commandResolverArguments); - - result.Should().NotBeNull(); - result.Args.Should().Be("\"arg with space\""); - } - - [Fact] - public void It_returns_a_CommandSpec_with_Args_as_stringEmpty_when_returning_a_CommandSpec_and_CommandArguments_are_null() - { - var testCommandPath = CommandResolverTestUtils.CreateNonRunnableTestCommand( - s_testDirectory, - "pathtestcommand1", - ".exe"); - - var staticPathEnvironmentMock = new Mock(); - staticPathEnvironmentMock.Setup(e => e - .GetCommandPath(It.IsAny(), It.IsAny())) - .Returns(testCommandPath); - - var pathCommandResolver = SetupPlatformPathCommandResolver(staticPathEnvironmentMock.Object, forceGeneric: true); - - var commandResolverArguments = new CommandResolverArguments() - { - CommandName = Path.GetFileNameWithoutExtension(testCommandPath), - CommandArguments = null - }; - - var result = pathCommandResolver.Resolve(commandResolverArguments); - - result.Should().NotBeNull(); - result.Args.Should().Be(string.Empty); - } - - [Fact] - public void It_prefers_EXE_over_CMD_when_two_command_candidates_exist_and_using_WindowsExePreferredCommandSpecFactory() - { - var environment = new EnvironmentProvider(new [] {".exe", ".cmd"}, new[] { s_testDirectory }); - var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); - - var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory); - - CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testDirectory, "extensionPreferenceCommand", ".exe"); - CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testDirectory, "extensionPreferenceCommand", ".cmd"); - - var commandResolverArguments = new CommandResolverArguments() - { - CommandName = "extensionPreferenceCommand", - CommandArguments = null - }; - - var result = pathCommandResolver.Resolve(commandResolverArguments); - - result.Should().NotBeNull(); - - var commandFile = Path.GetFileName(result.Path); - commandFile.Should().Be("extensionPreferenceCommand.exe"); - } - - [Fact] - public void It_wraps_command_with_CMD_EXE_when_command_has_CMD_Extension_and_using_WindowsExePreferredCommandSpecFactory() - { - var environment = new EnvironmentProvider(new [] {".cmd"}, new[] { s_testDirectory }); - var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); - - var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory); - - var testCommandPath = - CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testDirectory, "cmdWrapCommand", ".cmd"); - - var commandResolverArguments = new CommandResolverArguments() - { - CommandName = "cmdWrapCommand", - CommandArguments = null - }; - - var result = pathCommandResolver.Resolve(commandResolverArguments); - - result.Should().NotBeNull(); - - var commandFile = Path.GetFileName(result.Path); - commandFile.Should().Be("cmd.exe"); - - result.Args.Should().Contain(testCommandPath); - } - - private PathCommandResolver SetupPlatformPathCommandResolver( - IEnvironmentProvider environment = null, - bool forceGeneric = false) - { - environment = environment ?? new EnvironmentProvider(); - - IPlatformCommandSpecFactory platformCommandSpecFactory = new GenericPlatformCommandSpecFactory(); - - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows - && !forceGeneric) - { - platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); - } - - var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory); - - return pathCommandResolver; - } - } -} diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs index 758cc599e..2df9faf85 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependenciesCommandFactory.cs @@ -1,22 +1,13 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Linq; -using Xunit; -using Moq; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using Microsoft.DotNet.TestFramework; -using System.Threading; using FluentAssertions; +using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.TestFramework; +using Microsoft.DotNet.Tools.Test.Utilities; using NuGet.Frameworks; +using Xunit; namespace Microsoft.DotNet.Cli.Utils.Tests { diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependencyCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependencyCommandResolver.cs index 702d9190c..e9ba22554 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependencyCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectDependencyCommandResolver.cs @@ -2,27 +2,20 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Linq; -using Xunit; -using Moq; -using Microsoft.DotNet.Cli.Utils; +using FluentAssertions; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Threading; -using FluentAssertions; using NuGet.Frameworks; +using Xunit; namespace Microsoft.DotNet.Cli.Utils.Tests { public class GivenAProjectDependenciesCommandResolver { - private static readonly string s_liveProjectDirectory = + private static readonly string s_liveProjectDirectory = Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithDirectDependency"); [Fact] @@ -33,7 +26,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = null, - CommandArguments = new string[] {""}, + CommandArguments = new string[] { "" }, ProjectDirectory = "/some/directory", Configuration = "Debug", Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10 @@ -52,7 +45,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = "command", - CommandArguments = new string[] {""}, + CommandArguments = new string[] { "" }, ProjectDirectory = null, Configuration = "Debug", Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10 @@ -71,7 +64,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = "command", - CommandArguments = new string[] {""}, + CommandArguments = new string[] { "" }, ProjectDirectory = s_liveProjectDirectory, Configuration = "Debug", Framework = null @@ -90,7 +83,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = "command", - CommandArguments = new string[] {""}, + CommandArguments = new string[] { "" }, ProjectDirectory = s_liveProjectDirectory, Configuration = null, Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10 @@ -153,7 +146,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = "dotnet-hello", - CommandArguments = new [] { "arg with space"}, + CommandArguments = new[] { "arg with space" }, ProjectDirectory = s_liveProjectDirectory, Configuration = "Debug", Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10 @@ -203,7 +196,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var projectContext = ProjectContext.Create( s_liveProjectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10, - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); var depsFilePath = projectContext.GetOutputPaths("Debug", outputPath: AppContext.BaseDirectory).RuntimeFiles.DepsJson; @@ -232,7 +225,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var projectContext = ProjectContext.Create( s_liveProjectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10, - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); var depsFilePath = projectContext.GetOutputPaths("Debug", AppContext.BaseDirectory).RuntimeFiles.DepsJson; @@ -260,7 +253,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments); result.Should().NotBeNull(); - + result.Args.Should().Contain("dotnet-hello"); } diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectPathCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectPathCommandResolver.cs index 9c0a0ce6a..1bb32b2ce 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectPathCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectPathCommandResolver.cs @@ -2,20 +2,11 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Linq; -using Xunit; -using Moq; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Threading; using FluentAssertions; -using NuGet.Frameworks; +using Microsoft.DotNet.InternalAbstractions; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; namespace Microsoft.DotNet.Cli.Utils.Tests { @@ -31,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = null, - CommandArguments = new string[] {""}, + CommandArguments = new string[] { "" }, ProjectDirectory = "/some/directory" }; @@ -48,7 +39,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = "command", - CommandArguments = new string[] {""}, + CommandArguments = new string[] { "" }, ProjectDirectory = null }; @@ -130,7 +121,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = "projectpathtestcommand1", - CommandArguments = new [] { "arg with space"}, + CommandArguments = new[] { "arg with space" }, ProjectDirectory = s_testProjectDirectory }; @@ -143,7 +134,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests [Fact] public void It_resolves_commands_with_extensions_defined_in_InferredExtensions() { - var extensions = new string[] {".sh", ".cmd", ".foo", ".exe"}; + var extensions = new string[] { ".sh", ".cmd", ".foo", ".exe" }; var projectPathCommandResolver = SetupPlatformProjectPathCommandResolver(forceGeneric: true); foreach (var extension in extensions) @@ -166,7 +157,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandFileName = Path.GetFileName(result.Path); commandFileName.Should().Be("projectpathexttest" + extension); - } + } } [Fact] @@ -218,12 +209,12 @@ namespace Microsoft.DotNet.Cli.Utils.Tests public void It_wraps_command_with_CMD_EXE_when_command_has_CMD_Extension_and_using_WindowsExePreferredCommandSpecFactory() { - var environment = new EnvironmentProvider(new [] {".cmd"}); + var environment = new EnvironmentProvider(new[] { ".cmd" }); var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory); - var testCommandPath = + var testCommandPath = CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "cmdWrapCommand", ".cmd"); var commandResolverArguments = new CommandResolverArguments() @@ -250,7 +241,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests IPlatformCommandSpecFactory platformCommandSpecFactory = new GenericPlatformCommandSpecFactory(); - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows && !forceGeneric) { platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs index a8889d522..830a00e94 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs @@ -2,27 +2,15 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; -using System.Text; using System.Linq; -using Xunit; -using Moq; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Threading; using FluentAssertions; +using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.ProjectModel.Graph; +using Microsoft.DotNet.Tools.Test.Utilities; using NuGet.Frameworks; using NuGet.Versioning; -using NuGet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; -using Microsoft.DotNet.ProjectModel.Compilation; -using NuGet.ProjectModel; - -using LockFile = Microsoft.DotNet.ProjectModel.Graph.LockFile; +using Xunit; namespace Microsoft.DotNet.Cli.Utils.Tests { @@ -30,7 +18,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests { private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetCoreApp10; - private static readonly string s_liveProjectDirectory = + private static readonly string s_liveProjectDirectory = Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithToolDependency"); [Fact] @@ -41,7 +29,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = null, - CommandArguments = new string[] {""}, + CommandArguments = new string[] { "" }, ProjectDirectory = "/some/directory" }; @@ -58,7 +46,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = "command", - CommandArguments = new string[] {""}, + CommandArguments = new string[] { "" }, ProjectDirectory = null }; @@ -115,7 +103,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = "dotnet-portable", - CommandArguments = new [] { "arg with space"}, + CommandArguments = new[] { "arg with space" }, ProjectDirectory = s_liveProjectDirectory }; @@ -140,7 +128,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var result = projectToolsCommandResolver.Resolve(commandResolverArguments); result.Should().NotBeNull(); - + var commandPath = result.Args.Trim('"'); commandPath.Should().Contain("dotnet-portable.dll"); } @@ -163,8 +151,8 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot); var lockFilePath = toolPathCalculator.GetLockFilePath( - "dotnet-portable", - new NuGetVersion("1.0.0"), + "dotnet-portable", + new NuGetVersion("1.0.0"), s_toolPackageFramework); var directory = Path.GetDirectoryName(lockFilePath); @@ -181,7 +169,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var result = projectToolsCommandResolver.Resolve(commandResolverArguments); result.Should().NotBeNull(); - + depsJsonFile = Directory .EnumerateFiles(directory) .FirstOrDefault(p => Path.GetFileName(p).EndsWith(FileNameSuffixes.DepsJson)); @@ -198,8 +186,8 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot); var lockFilePath = toolPathCalculator.GetLockFilePath( - "dotnet-portable", - new NuGetVersion("1.0.0"), + "dotnet-portable", + new NuGetVersion("1.0.0"), s_toolPackageFramework); var lockFile = LockFileReader.Read(lockFilePath, designTime: false); diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenARootedCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenARootedCommandResolver.cs index bcaba5148..adcd3f374 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenARootedCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenARootedCommandResolver.cs @@ -1,21 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Linq; -using Xunit; -using Moq; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Threading; using FluentAssertions; -using NuGet.Frameworks; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; namespace Microsoft.DotNet.Cli.Utils.Tests { @@ -78,7 +66,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = "/some/rooted/path", - CommandArguments = new [] { "arg with space"} + CommandArguments = new[] { "arg with space" } }; var result = rootedCommandResolver.Resolve(commandResolverArguments); diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAScriptCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAScriptCommandResolver.cs index b8c8d996f..58537e863 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAScriptCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAScriptCommandResolver.cs @@ -1,21 +1,10 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using Xunit; -using Moq; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Threading; using FluentAssertions; -using NuGet.Frameworks; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; namespace Microsoft.DotNet.Cli.Utils.Tests { @@ -33,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests resolvers.Select(r => r.GetType()) .Should() .ContainInOrder( - new []{ + new[]{ typeof(RootedCommandResolver), typeof(MuxerCommandResolver), typeof(ProjectPathCommandResolver), diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAnAppBaseCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAnAppBaseCommandResolver.cs index 2f1bd56db..7aced0131 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAnAppBaseCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAnAppBaseCommandResolver.cs @@ -2,20 +2,11 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Linq; -using Xunit; -using Moq; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Threading; using FluentAssertions; -using NuGet.Frameworks; +using Microsoft.DotNet.InternalAbstractions; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; namespace Microsoft.DotNet.Cli.Utils.Tests { @@ -107,7 +98,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests var commandResolverArguments = new CommandResolverArguments() { CommandName = "appbasetestcommand1", - CommandArguments = new [] { "arg with space"} + CommandArguments = new[] { "arg with space" } }; var result = appBaseCommandResolver.Resolve(commandResolverArguments); @@ -163,12 +154,12 @@ namespace Microsoft.DotNet.Cli.Utils.Tests public void It_wraps_command_with_CMD_EXE_when_command_has_CMD_Extension_and_using_WindowsExePreferredCommandSpecFactory() { - var environment = new EnvironmentProvider(new [] {".cmd"}); + var environment = new EnvironmentProvider(new[] { ".cmd" }); var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory); - var testCommandPath = + var testCommandPath = CommandResolverTestUtils.CreateNonRunnableTestCommand(AppContext.BaseDirectory, "cmdWrapCommand", ".cmd"); var commandResolverArguments = new CommandResolverArguments() @@ -193,9 +184,9 @@ namespace Microsoft.DotNet.Cli.Utils.Tests { environment = environment ?? new EnvironmentProvider(); - IPlatformCommandSpecFactory platformCommandSpecFactory = new GenericPlatformCommandSpecFactory(); + IPlatformCommandSpecFactory platformCommandSpecFactory = new GenericPlatformCommandSpecFactory(); - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows && !forceGeneric) { platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/StreamForwarderTests.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/StreamForwarderTests.cs index 74bae879f..f59b81ec1 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/StreamForwarderTests.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/StreamForwarderTests.cs @@ -4,20 +4,16 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using Xunit; using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Threading; +using Xunit; namespace StreamForwarderTests { public class StreamForwarderTests : TestBase { - private static readonly string s_rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + private static readonly string s_rid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); private static readonly string s_testProjectRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects"); private TempDirectory _root; @@ -57,7 +53,7 @@ namespace StreamForwarderTests [InlineData("123")] [InlineData("123\n")] public void TestNoForwardingNoCapture(string inputStr) - { + { TestCapturingAndForwardingHelper(ForwardOptions.None, inputStr, null, new string[0]); } @@ -65,11 +61,11 @@ namespace StreamForwarderTests [MemberData("ForwardingTheoryVariations")] public void TestForwardingOnly(string inputStr, string[] expectedWrites) { - for(int i = 0; i < expectedWrites.Length; ++i) + for (int i = 0; i < expectedWrites.Length; ++i) { expectedWrites[i] += Environment.NewLine; } - + TestCapturingAndForwardingHelper(ForwardOptions.WriteLine, inputStr, null, expectedWrites); } @@ -77,13 +73,13 @@ namespace StreamForwarderTests [MemberData("ForwardingTheoryVariations")] public void TestCaptureOnly(string inputStr, string[] expectedWrites) { - for(int i = 0; i < expectedWrites.Length; ++i) + for (int i = 0; i < expectedWrites.Length; ++i) { expectedWrites[i] += Environment.NewLine; } var expectedCaptured = string.Join("", expectedWrites); - + TestCapturingAndForwardingHelper(ForwardOptions.Capture, inputStr, expectedCaptured, new string[0]); } @@ -91,7 +87,7 @@ namespace StreamForwarderTests [MemberData("ForwardingTheoryVariations")] public void TestCaptureAndForwardingTogether(string inputStr, string[] expectedWrites) { - for(int i = 0; i < expectedWrites.Length; ++i) + for (int i = 0; i < expectedWrites.Length; ++i) { expectedWrites[i] += Environment.NewLine; } diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs index a16de4d69..0ea9d233b 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs @@ -1,13 +1,13 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; -using Microsoft.Extensions.PlatformAbstractions; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.InternalAbstractions; +using Microsoft.DotNet.ProjectModel; namespace Microsoft.DotNet.Tools.Test.Utilities { @@ -69,10 +69,10 @@ namespace Microsoft.DotNet.Tools.Test.Utilities string config = string.IsNullOrEmpty(_config) ? "Debug" : _config; string framework = string.IsNullOrEmpty(_framework) ? _project.GetTargetFrameworks().First().FrameworkName.GetShortFolderName() : _framework; - + if (!portable) { - var runtime = string.IsNullOrEmpty(_runtime) ? PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier() : _runtime; + var runtime = string.IsNullOrEmpty(_runtime) ? RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier() : _runtime; return Path.Combine(config, framework, runtime, PublishSubfolderName); } else @@ -120,7 +120,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}"; private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o \"{_output}\""; private string ConfigOption => string.IsNullOrEmpty(_config) ? "" : $"-c {_output}"; - private string NoBuildFlag => _noBuild ? "--no-build" :""; + private string NoBuildFlag => _noBuild ? "--no-build" : ""; private string BuildBasePathOption => string.IsNullOrEmpty(_buidBasePathDirectory) ? "" : $"-b {_buidBasePathDirectory}"; } } diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/WindowsOnlyFactAttribute.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/WindowsOnlyFactAttribute.cs index 07341b2a7..146316868 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/WindowsOnlyFactAttribute.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/WindowsOnlyFactAttribute.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.InternalAbstractions; using Xunit; namespace Microsoft.DotNet.Tools.Test.Utilities @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities { public WindowsOnlyFactAttribute() { - if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) { this.Skip = "This test requires windows to run"; } @@ -21,7 +21,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities { public WindowsOnlyTheoryAttribute() { - if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) { this.Skip = "This test requires windows to run"; } diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs b/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs index 2eb0e095f..c6727db7f 100644 --- a/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs +++ b/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs @@ -5,11 +5,9 @@ using System; using System.Collections.Generic; using System.IO; using FluentAssertions; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.Extensions.DependencyModel.Resolution; -using Microsoft.Extensions.PlatformAbstractions; -using Moq; using Xunit; - using F = Microsoft.Extensions.DependencyModel.Tests.TestLibraryFactory; namespace Microsoft.Extensions.DependencyModel.Tests @@ -21,13 +19,11 @@ namespace Microsoft.Extensions.DependencyModel.Tests [Fact] public void SholdUseEnvironmentVariableToGetDefaultLocation() { - var runtime = new Mock(); - var environment = EnvironmentMockBuilder.Create() .AddVariable("NUGET_PACKAGES", PackagesPath) .Build(); - var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(runtime.Object, environment); + var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(Platform.Unknown, environment); result.Should().Be(PackagesPath); } @@ -35,28 +31,22 @@ namespace Microsoft.Extensions.DependencyModel.Tests [Fact] public void SholdUseNugetUnderUserProfileOnWindows() { - var runtime = new Mock(); - runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Windows); - var environment = EnvironmentMockBuilder.Create() .AddVariable("USERPROFILE", "User Profile") .Build(); - var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(runtime.Object, environment); + var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(Platform.Windows, environment); result.Should().Be(Path.Combine("User Profile", ".nuget", "packages")); } [Fact] public void SholdUseNugetUnderHomeOnNonWindows() { - var runtime = new Mock(); - runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Linux); - var environment = EnvironmentMockBuilder.Create() .AddVariable("HOME", "User Home") .Build(); - var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(runtime.Object, environment); + var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(Platform.Linux, environment); result.Should().Be(Path.Combine("User Home", ".nuget", "packages")); } diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/ReferenceAssemblyResolverTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/ReferenceAssemblyResolverTests.cs index 2b4f53d7d..5895ea994 100644 --- a/test/Microsoft.Extensions.DependencyModel.Tests/ReferenceAssemblyResolverTests.cs +++ b/test/Microsoft.Extensions.DependencyModel.Tests/ReferenceAssemblyResolverTests.cs @@ -5,11 +5,9 @@ using System; using System.Collections.Generic; using System.IO; using FluentAssertions; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.Extensions.DependencyModel.Resolution; -using Microsoft.Extensions.PlatformAbstractions; -using Moq; using Xunit; - using F = Microsoft.Extensions.DependencyModel.Tests.TestLibraryFactory; @@ -34,53 +32,41 @@ namespace Microsoft.Extensions.DependencyModel.Tests [Fact] public void UsesEnvironmentVariableForDefaultPath() { - var runtime = new Mock(); - runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Windows); - var environment = EnvironmentMockBuilder.Create() .AddVariable("DOTNET_REFERENCE_ASSEMBLIES_PATH", ReferencePath) .Build(); - var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, FileSystemMockBuilder.Empty, environment); + var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(FileSystemMockBuilder.Empty, Platform.Windows, environment); result.Should().Be(ReferencePath); } [Fact] public void LooksOnlyOnEnvironmentVariableOnNonWindows() { - var runtime = new Mock(); - runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Linux); - - var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, FileSystemMockBuilder.Empty, EnvironmentMockBuilder.Empty); + var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(FileSystemMockBuilder.Empty, Platform.Linux, EnvironmentMockBuilder.Empty); result.Should().BeNull(); } [Fact] public void ReturnsProgramFiles86AsDefaultLocationOnWin64() { - var runtime = new Mock(); - runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Windows); - var environment = EnvironmentMockBuilder.Create() .AddVariable("ProgramFiles(x86)", "Program Files (x86)") .AddVariable("ProgramFiles", "Program Files") .Build(); - var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, FileSystemMockBuilder.Empty, environment); + var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(FileSystemMockBuilder.Empty, Platform.Windows, environment); result.Should().Be(Path.Combine("Program Files (x86)", "Reference Assemblies", "Microsoft", "Framework")); } [Fact] public void ReturnsProgramFilesAsDefaultLocationOnWin32() { - var runtime = new Mock(); - runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Windows); - var environment = EnvironmentMockBuilder.Create() .AddVariable("ProgramFiles", "Program Files") .Build(); - var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, FileSystemMockBuilder.Empty, environment); + var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(FileSystemMockBuilder.Empty, Platform.Windows, environment); result.Should().Be(Path.Combine("Program Files", "Reference Assemblies", "Microsoft", "Framework")); } @@ -92,14 +78,11 @@ namespace Microsoft.Extensions.DependencyModel.Tests .AddFiles(net20Path, "some.dll") .Build(); - var runtime = new Mock(); - runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Windows); - var environment = EnvironmentMockBuilder.Create() .AddVariable("WINDIR", "Windows") .Build(); - var result = ReferenceAssemblyPathResolver.GetFallbackSearchPaths(fileSystem, runtime.Object, environment); + var result = ReferenceAssemblyPathResolver.GetFallbackSearchPaths(fileSystem, Platform.Windows, environment); result.Should().Contain(net20Path); } diff --git a/test/Performance/HelloWorld.cs b/test/Performance/HelloWorld.cs index d67cc3216..d2421a688 100644 --- a/test/Performance/HelloWorld.cs +++ b/test/Performance/HelloWorld.cs @@ -3,13 +3,8 @@ using System; using System.IO; -using System.Linq; -using System.Runtime.InteropServices; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Xunit.Performance; -using Xunit; -using System.Diagnostics; namespace Microsoft.DotNet.Tests.Performance { diff --git a/test/binding-redirects.Tests/BindingRedirectTests.cs b/test/binding-redirects.Tests/BindingRedirectTests.cs index 57cdf99f7..59c9b6de4 100644 --- a/test/binding-redirects.Tests/BindingRedirectTests.cs +++ b/test/binding-redirects.Tests/BindingRedirectTests.cs @@ -6,14 +6,10 @@ using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Xml.Linq; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.DotNet.TestFramework; -using Microsoft.Extensions.PlatformAbstractions; -using Xunit; using FluentAssertions; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; namespace Microsoft.DotNet.Tests { diff --git a/test/binding-redirects.Tests/TestSetupFixture.cs b/test/binding-redirects.Tests/TestSetupFixture.cs index 7394a1530..70bf7e824 100644 --- a/test/binding-redirects.Tests/TestSetupFixture.cs +++ b/test/binding-redirects.Tests/TestSetupFixture.cs @@ -1,16 +1,10 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Tools.Test.Utilities; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.TestFramework; -using Microsoft.Extensions.PlatformAbstractions; -using Xunit; +using Microsoft.DotNet.Tools.Test.Utilities; namespace Microsoft.DotNet.Tests { @@ -21,7 +15,7 @@ namespace Microsoft.DotNet.Tests private const string AppWithConfig = "AppWithRedirectsAndConfig"; private const string AppWithoutConfig = "AppWithRedirectsNoConfig"; - private string _Runtime = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + private string _Runtime = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); private string _desktopProjectsRoot = Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects"); private string _buildRelativePath; private string _appWithConfigProjectRoot; diff --git a/test/dotnet-build.Tests/BuildOutputTests.cs b/test/dotnet-build.Tests/BuildOutputTests.cs index 34f83edcb..1e97eb5fa 100644 --- a/test/dotnet-build.Tests/BuildOutputTests.cs +++ b/test/dotnet-build.Tests/BuildOutputTests.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using FluentAssertions; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; using Newtonsoft.Json.Linq; using NuGet.Frameworks; using Xunit; @@ -69,7 +69,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests var contexts = ProjectContext.CreateContextForEachFramework( _testAppDirDirInfo.FullName, null, - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); _runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier; } @@ -177,9 +177,9 @@ namespace Microsoft.DotNet.Tools.Builder.Tests } [Theory] -// [InlineData("net20", false, true)] -// [InlineData("net40", true, true)] -// [InlineData("net461", true, true)] + // [InlineData("net20", false, true)] + // [InlineData("net40", true, true)] + // [InlineData("net461", true, true)] [InlineData("netstandard1.5", true, false)] public void MultipleFrameworks_ShouldHaveValidTargetFrameworkAttribute(string frameworkName, bool shouldHaveTargetFrameworkAttribute, bool windowsOnly) { diff --git a/test/dotnet-build.Tests/BuildStandAloneTests.cs b/test/dotnet-build.Tests/BuildStandAloneTests.cs index 0d53cdedd..042ee8d77 100644 --- a/test/dotnet-build.Tests/BuildStandAloneTests.cs +++ b/test/dotnet-build.Tests/BuildStandAloneTests.cs @@ -2,14 +2,14 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.IO; -using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.DotNet.ProjectModel; -using Microsoft.Extensions.PlatformAbstractions; -using Xunit; using System.Linq; -using Microsoft.DotNet.TestFramework; -using Newtonsoft.Json.Linq; using FluentAssertions; +using Microsoft.DotNet.InternalAbstractions; +using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.TestFramework; +using Microsoft.DotNet.Tools.Test.Utilities; +using Newtonsoft.Json.Linq; +using Xunit; namespace Microsoft.DotNet.Tools.Builder.Tests { @@ -72,7 +72,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests var contexts = ProjectContext.CreateContextForEachFramework( projectPath, null, - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); var runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier; diff --git a/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs b/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs index 473e644c8..bd0a9090a 100644 --- a/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs +++ b/test/dotnet-compile.UnitTests/GivenThatICareAboutScriptVariablesFromAManagedCompiler.cs @@ -4,14 +4,13 @@ using System; using System.Collections.Generic; using System.IO; +using FluentAssertions; +using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Moq; using NuGet.Frameworks; using Xunit; -using Microsoft.DotNet.Cli.Utils; -using FluentAssertions; -using System.Linq; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Compiler.Tests { @@ -70,7 +69,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests [Fact] public void It_passes_a_RuntimeOutputDir_variable_to_the_pre_compile_scripts_if_rid_is_set_in_the_ProjectContext() { - var rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + var rid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); var fixture = ScriptVariablesFixture.GetFixtureWithRids(rid); fixture.PreCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir"); fixture.PreCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir); @@ -129,7 +128,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests [Fact] public void It_passes_a_RuntimeOutputDir_variable_to_the_post_compile_scripts_if_rid_is_set_in_the_ProjectContext() { - var rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + var rid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); var fixture = ScriptVariablesFixture.GetFixtureWithRids(rid); fixture.PostCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir"); fixture.PostCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir); diff --git a/test/dotnet-publish.Tests/PublishDesktopTests.cs b/test/dotnet-publish.Tests/PublishDesktopTests.cs index 9ef5106da..afea20671 100644 --- a/test/dotnet-publish.Tests/PublishDesktopTests.cs +++ b/test/dotnet-publish.Tests/PublishDesktopTests.cs @@ -1,14 +1,11 @@ -using System.Diagnostics; -using System.IO; -using System.Linq; +using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading.Tasks; using FluentAssertions; -using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; using Xunit; namespace Microsoft.DotNet.Tools.Publish.Tests @@ -28,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests [InlineData("win7-x86", "the-win-x86-version.txt")] public async Task DesktopApp_WithDependencyOnNativePackage_ProducesExpectedOutput(string runtime, string expectedOutputName) { - if(string.IsNullOrEmpty(expectedOutputName)) + if (string.IsNullOrEmpty(expectedOutputName)) { expectedOutputName = $"the-win-{RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant()}-version.txt"; } @@ -57,7 +54,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests [InlineData("KestrelDesktop", "http://localhost:20207", "win7-x86", "libuv.dll", false)] public async Task DesktopApp_WithKestrel_WorksWhenPublished(string project, string url, string runtime, string libuvName, bool forceRunnable) { - var runnable = forceRunnable || string.IsNullOrEmpty(runtime) || (PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier().Contains(runtime)); + var runnable = forceRunnable || string.IsNullOrEmpty(runtime) || (RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier().Contains(runtime)); var testInstance = GetTestInstance() .WithLockFiles(); diff --git a/test/dotnet-publish.Tests/PublishTests.cs b/test/dotnet-publish.Tests/PublishTests.cs index d2463d901..0603a6ff3 100644 --- a/test/dotnet-publish.Tests/PublishTests.cs +++ b/test/dotnet-publish.Tests/PublishTests.cs @@ -1,15 +1,14 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; -using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; using Xunit; -using System; namespace Microsoft.DotNet.Tools.Publish.Tests { @@ -65,11 +64,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests { new object[] { "1", "", "", "", "" }, new object[] { "2", "netcoreapp1.0", "", "", "" }, - new object[] { "3", "", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "", "" }, + new object[] { "3", "", RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(), "", "" }, new object[] { "4", "", "", "Release", "" }, new object[] { "5", "", "", "", "some/dir"}, new object[] { "6", "", "", "", "some/dir/with spaces" }, - new object[] { "7", "netcoreapp1.0", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "Debug", "some/dir" }, + new object[] { "7", "netcoreapp1.0", RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(), "Debug", "some/dir" }, }; } } @@ -231,7 +230,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll"); publishCommand.GetOutputDirectory().Delete(true); - publishCommand = new PublishCommand(lesserTestProject, "netstandard1.5", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier()); + publishCommand = new PublishCommand(lesserTestProject, "netstandard1.5", RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier()); publishCommand.Execute().Should().Pass(); publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll"); diff --git a/test/dotnet-resgen.Tests/Microsoft.DotNet.Tools.Resgen.Tests.cs b/test/dotnet-resgen.Tests/Microsoft.DotNet.Tools.Resgen.Tests.cs index bbff9d6e6..6d885301b 100644 --- a/test/dotnet-resgen.Tests/Microsoft.DotNet.Tools.Resgen.Tests.cs +++ b/test/dotnet-resgen.Tests/Microsoft.DotNet.Tools.Resgen.Tests.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; using Xunit; using System; diff --git a/test/dotnet-test.Tests/GivenThatWeWantToRunTestsForMultipleTFMsInTheConsole.cs b/test/dotnet-test.Tests/GivenThatWeWantToRunTestsForMultipleTFMsInTheConsole.cs index 882f08bb1..b3ab32ac7 100644 --- a/test/dotnet-test.Tests/GivenThatWeWantToRunTestsForMultipleTFMsInTheConsole.cs +++ b/test/dotnet-test.Tests/GivenThatWeWantToRunTestsForMultipleTFMsInTheConsole.cs @@ -5,10 +5,10 @@ using System; using System.IO; using System.Linq; using FluentAssertions; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; using Xunit; namespace Microsoft.Dotnet.Tools.Test.Tests @@ -28,7 +28,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests var contexts = ProjectContext.CreateContextForEachFramework( _projectFilePath, null, - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); // Restore the project again in the destination to resolve projects // Since the lock file has project relative paths in it, those will be broken @@ -36,7 +36,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.Execute().Should().Pass(); _defaultNetCoreAppOutputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "netcoreapp1.0"); - _defaultNet451OutputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "net451", PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers().First()); + _defaultNet451OutputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "net451", RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers().First()); } [WindowsOnlyFact] @@ -105,7 +105,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests [WindowsOnlyFact] public void It_skips_build_when_the_no_build_flag_is_passed_for_net451() { - var rid = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers().First(); + var rid = RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers().First(); var buildCommand = new BuildCommand(_projectFilePath); var result = buildCommand.Execute($"-f net451 -r {rid} -o {_defaultNet451OutputPath}"); result.Should().Pass(); diff --git a/test/dotnet-test.Tests/GivenThatWeWantToRunTestsInTheConsole.cs b/test/dotnet-test.Tests/GivenThatWeWantToRunTestsInTheConsole.cs index 33e97fdef..70823069b 100644 --- a/test/dotnet-test.Tests/GivenThatWeWantToRunTestsInTheConsole.cs +++ b/test/dotnet-test.Tests/GivenThatWeWantToRunTestsInTheConsole.cs @@ -3,12 +3,11 @@ using System; using System.IO; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.TestFramework; -using Microsoft.Extensions.PlatformAbstractions; -using Xunit; using Microsoft.DotNet.Tools.Test.Utilities; -using System.Linq; +using Xunit; namespace Microsoft.Dotnet.Tools.Test.Tests { @@ -26,7 +25,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests var contexts = ProjectContext.CreateContextForEachFramework( _projectFilePath, null, - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); // Restore the project again in the destination to resolve projects // Since the lock file has project relative paths in it, those will be broken diff --git a/test/dotnet-test.Tests/GivenThatWeWantToUseDotnetTestE2EInDesignTime.cs b/test/dotnet-test.Tests/GivenThatWeWantToUseDotnetTestE2EInDesignTime.cs index dcbe2aca0..c76238c85 100644 --- a/test/dotnet-test.Tests/GivenThatWeWantToUseDotnetTestE2EInDesignTime.cs +++ b/test/dotnet-test.Tests/GivenThatWeWantToUseDotnetTestE2EInDesignTime.cs @@ -1,14 +1,13 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.IO; +using FluentAssertions; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; -using System.IO; -using FluentAssertions; using Xunit; -using Microsoft.Extensions.PlatformAbstractions; -using System.Linq; namespace Microsoft.Dotnet.Tools.Test.Tests { @@ -25,7 +24,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests var contexts = ProjectContext.CreateContextForEachFramework( _projectFilePath, null, - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); // Restore the project again in the destination to resolve projects // Since the lock file has project relative paths in it, those will be broken diff --git a/test/dotnet-test.Tests/GivenThatWeWantToUseDotnetTestE2EInDesignTimeForMultipleTFms.cs b/test/dotnet-test.Tests/GivenThatWeWantToUseDotnetTestE2EInDesignTimeForMultipleTFms.cs index 84635d901..dd25f1dbe 100644 --- a/test/dotnet-test.Tests/GivenThatWeWantToUseDotnetTestE2EInDesignTimeForMultipleTFms.cs +++ b/test/dotnet-test.Tests/GivenThatWeWantToUseDotnetTestE2EInDesignTimeForMultipleTFms.cs @@ -3,11 +3,11 @@ using System.IO; using System.Linq; +using FluentAssertions; +using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using FluentAssertions; using Xunit; namespace Microsoft.Dotnet.Tools.Test.Tests @@ -26,7 +26,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests var contexts = ProjectContext.CreateContextForEachFramework( _projectFilePath, null, - PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); // Restore the project again in the destination to resolve projects // Since the lock file has project relative paths in it, those will be broken @@ -39,9 +39,9 @@ namespace Microsoft.Dotnet.Tools.Test.Tests result.Should().Pass(); - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) + if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { - var rid = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers().First(); + var rid = RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers().First(); _net451OutputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "net451", rid); result = buildCommand.Execute($"-f net451 -r {rid} -o {_net451OutputPath}"); result.Should().Pass(); @@ -71,7 +71,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests using (var adapter = new Adapter("TestDiscovery.Start")) { adapter.Listen(); - var rid = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers().First(); + var rid = RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers().First(); var testCommand = new DotnetTestCommand(); var result = testCommand.Execute($"{_projectFilePath} -f net451 -r {rid} -o {_net451OutputPath} --port {adapter.Port} --no-build"); @@ -110,7 +110,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests adapter.Listen(); var testCommand = new DotnetTestCommand(); - var rid = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers().First(); + var rid = RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers().First(); var result = testCommand.Execute($"{_projectFilePath} -f net451 -r {rid} -o {_net451OutputPath} --port {adapter.Port} --no-build"); result.Should().Pass(); diff --git a/test/dotnet.Tests/PackagedCommandTests.cs b/test/dotnet.Tests/PackagedCommandTests.cs index 5c2869b58..e17e6f7a2 100644 --- a/test/dotnet.Tests/PackagedCommandTests.cs +++ b/test/dotnet.Tests/PackagedCommandTests.cs @@ -4,12 +4,12 @@ using System; using System.Collections.Generic; using System.IO; +using System.Runtime.InteropServices; +using FluentAssertions; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Test.Utilities; -using Microsoft.Extensions.PlatformAbstractions; -using System.Runtime.InteropServices; +using Microsoft.DotNet.InternalAbstractions; using Xunit; -using FluentAssertions; namespace Microsoft.DotNet.Tests { @@ -76,9 +76,9 @@ namespace Microsoft.DotNet.Tests CommandResult result = new DependencyToolInvokerCommand { WorkingDirectory = appDirectory } .ExecuteWithCapturedOutput("tool-with-output-name", framework, string.Empty); - result.Should().HaveStdOutContaining("Tool with output name!"); - result.Should().NotHaveStdErr(); - result.Should().Pass(); + result.Should().HaveStdOutContaining("Tool with output name!"); + result.Should().NotHaveStdErr(); + result.Should().Pass(); } // need conditional theories so we can skip on non-Windows @@ -101,11 +101,11 @@ namespace Microsoft.DotNet.Tests CommandResult result = new DependencyToolInvokerCommand { WorkingDirectory = appDirectory } .ExecuteWithCapturedOutput("desktop-and-portable", framework, args); - result.Should().HaveStdOutContaining(framework); - result.Should().HaveStdOutContaining(args); - result.Should().HaveStdOutContaining(expectedDependencyToolPath); - result.Should().NotHaveStdErr(); - result.Should().Pass(); + result.Should().HaveStdOutContaining(framework); + result.Should().HaveStdOutContaining(args); + result.Should().HaveStdOutContaining(expectedDependencyToolPath); + result.Should().NotHaveStdErr(); + result.Should().Pass(); } [Fact] @@ -123,8 +123,8 @@ namespace Microsoft.DotNet.Tests { get { - var rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); - var projectOutputPath = $"AppWithDirectDependencyDesktopAndPortable\\bin\\Debug\\net451\\{rid}\\dotnet-desktop-and-portable.exe"; + var rid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); + var projectOutputPath = $"AppWithDirectDependencyDesktopAndPortable\\bin\\Debug\\net451\\{rid}\\dotnet-desktop-and-portable.exe"; return new[] { new object[] { ".NETCoreApp,Version=v1.0", "CoreFX", "lib\\netcoreapp1.0\\dotnet-desktop-and-portable.dll" }, diff --git a/tools/RuntimeGraphGenerator/Program.cs b/tools/RuntimeGraphGenerator/Program.cs index ebf1ff29a..cbaddbe9f 100644 --- a/tools/RuntimeGraphGenerator/Program.cs +++ b/tools/RuntimeGraphGenerator/Program.cs @@ -4,15 +4,12 @@ using System; using System.Collections.Generic; using System.CommandLine; -using Microsoft.DotNet.Cli.Utils; using System.IO; -using System.Runtime.Versioning; +using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.Extensions.DependencyModel; using NuGet.Frameworks; -using NuGet.Packaging; -using NuGet.Versioning; -using Microsoft.DotNet.ProjectModel.Graph; namespace RuntimeGraphGenerator { diff --git a/tools/RuntimeGraphGenerator/RuntimeGraphManager.cs b/tools/RuntimeGraphGenerator/RuntimeGraphManager.cs index 81d9da1c1..88e290307 100644 --- a/tools/RuntimeGraphGenerator/RuntimeGraphManager.cs +++ b/tools/RuntimeGraphGenerator/RuntimeGraphManager.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; +using System.IO; using System.Linq; -using System.Threading.Tasks; using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.DotNet.ProjectModel.Graph; -using NuGet.RuntimeModel; -using System.IO; using Microsoft.Extensions.DependencyModel; +using NuGet.RuntimeModel; namespace Microsoft.DotNet.ProjectModel { diff --git a/tools/RuntimeGraphGenerator/project.json b/tools/RuntimeGraphGenerator/project.json index 024a16e11..93f760d7f 100644 --- a/tools/RuntimeGraphGenerator/project.json +++ b/tools/RuntimeGraphGenerator/project.json @@ -10,7 +10,6 @@ "System.Runtime.Serialization.Json": "4.0.2-rc2-24027", "Microsoft.DotNet.ProjectModel": "1.0.0-*", "Microsoft.DotNet.Cli.Utils": "1.0.0-*", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-20100", "Microsoft.NETCore.ConsoleHost": "1.0.0-rc2-24027", "NETStandard.Library": "1.5.0-rc2-24027" },