Replaces references to Microsoft.Extensions.PlatformAbstractions with Microsoft.Extensions.PlatformAbstractions.Internal

This commit is contained in:
Pranav K 2016-04-28 16:30:32 -07:00
parent 2a49edbb6e
commit 1e753f7781
110 changed files with 886 additions and 954 deletions

View file

@ -109,6 +109,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-run.Tests", "test\do
EndProject EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Performance", "test\Performance\Performance.xproj", "{6A3095FF-A7C5-4300-85A9-C025C384401D}" Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Performance", "test\Performance\Performance.xproj", "{6A3095FF-A7C5-4300-85A9-C025C384401D}"
EndProject 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 Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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|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.ActiveCfg = Release|Any CPU
{6A3095FF-A7C5-4300-85A9-C025C384401D}.RelWithDebInfo|x64.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -828,5 +846,6 @@ Global
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F} = {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} {6A3095FF-A7C5-4300-85A9-C025C384401D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{27DBF851-F2E3-4FD5-BF4D-A73C81933283} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View file

@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Filter;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.PlatformAbstractions;
namespace SampleApp namespace SampleApp
{ {
@ -21,7 +20,7 @@ namespace SampleApp
private static string Args { get; set; } private static string Args { get; set; }
private static CancellationTokenSource ServerCancellationTokenSource { 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<IKestrelServerInformation>(); var ksi = app.ServerFeatures.Get<IKestrelServerInformation>();
ksi.NoDelay = true; ksi.NoDelay = true;

View file

@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Filter;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.PlatformAbstractions;
namespace SampleApp namespace SampleApp
{ {
@ -21,7 +20,7 @@ namespace SampleApp
private static string Args { get; set; } private static string Args { get; set; }
private static CancellationTokenSource ServerCancellationTokenSource { 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<IKestrelServerInformation>(); var ksi = app.ServerFeatures.Get<IKestrelServerInformation>();
ksi.NoDelay = true; ksi.NoDelay = true;

View file

@ -1,5 +1,5 @@
using System; using System;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Build.Framework namespace Microsoft.DotNet.Cli.Build.Framework
{ {
@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
{ {
get get
{ {
var archName = PlatformServices.Default.Runtime.RuntimeArchitecture; var archName = RuntimeEnvironment.RuntimeArchitecture;
return string.Equals(archName, "x86", StringComparison.OrdinalIgnoreCase); return string.Equals(archName, "x86", StringComparison.OrdinalIgnoreCase);
} }
} }
@ -26,7 +26,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
{ {
get get
{ {
var archName = PlatformServices.Default.Runtime.RuntimeArchitecture; var archName = RuntimeEnvironment.RuntimeArchitecture;
return string.Equals(archName, "x64", StringComparison.OrdinalIgnoreCase); return string.Equals(archName, "x64", StringComparison.OrdinalIgnoreCase);
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Build.Framework namespace Microsoft.DotNet.Cli.Build.Framework
{ {
@ -34,7 +34,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
{ {
get get
{ {
var osname = PlatformServices.Default.Runtime.OperatingSystem; var osname = RuntimeEnvironment.OperatingSystem;
return string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase); return string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase);
} }
} }
@ -43,7 +43,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
{ {
get get
{ {
var osname = PlatformServices.Default.Runtime.OperatingSystem; var osname = RuntimeEnvironment.OperatingSystem;
return string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase); return string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase);
} }
} }
@ -52,7 +52,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
{ {
get get
{ {
var osname = PlatformServices.Default.Runtime.OperatingSystem; var osname = RuntimeEnvironment.OperatingSystem;
return string.Equals(osname, "rhel", StringComparison.OrdinalIgnoreCase); return string.Equals(osname, "rhel", StringComparison.OrdinalIgnoreCase);
} }
} }
@ -69,7 +69,7 @@ namespace Microsoft.DotNet.Cli.Build.Framework
{ {
get get
{ {
var osname = PlatformServices.Default.Runtime.OperatingSystem; var osname = RuntimeEnvironment.OperatingSystem;
return string.Equals(osname, "debian", StringComparison.OrdinalIgnoreCase); return string.Equals(osname, "debian", StringComparison.OrdinalIgnoreCase);
} }
} }

View file

@ -1,10 +1,19 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"compilationOptions": {
"warningsAsErrors": true,
"allowUnsafe": true
},
"dependencies": { "dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027", "NETStandard.Library": "1.5.0-rc2-24027",
"System.Diagnostics.Process": "4.1.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": { "frameworks": {
"netstandard1.3": { "netstandard1.3": {
"imports": "dnxcore50" "imports": "dnxcore50"

View file

@ -1,18 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
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 Newtonsoft.Json; 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 namespace Microsoft.DotNet.Cli.Build
{ {
@ -37,9 +34,9 @@ namespace Microsoft.DotNet.Cli.Build
}; };
public static string HostPackagePlatformRid => HostPackageSupportedRids[ public static string HostPackagePlatformRid => HostPackageSupportedRids[
(PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
? $"win7-{PlatformServices.Default.Runtime.RuntimeArchitecture}" ? $"win7-{RuntimeEnvironment.RuntimeArchitecture}"
: PlatformServices.Default.Runtime.GetRuntimeIdentifier()]; : RuntimeEnvironment.GetRuntimeIdentifier()];
public static readonly Dictionary<string, string> HostPackageSupportedRids = new Dictionary<string, string>() public static readonly Dictionary<string, string> HostPackageSupportedRids = new Dictionary<string, string>()
{ {
@ -479,13 +476,13 @@ namespace Microsoft.DotNet.Cli.Build
string SharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion"); string SharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
string sharedFrameworkRid; 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 else
{ {
sharedFrameworkRid = PlatformServices.Default.Runtime.GetRuntimeIdentifier(); sharedFrameworkRid = RuntimeEnvironment.GetRuntimeIdentifier();
} }
string SharedFrameworkSourceRoot = GenerateSharedFrameworkProject(c, SharedFrameworkTemplateSourceRoot, sharedFrameworkRid); string SharedFrameworkSourceRoot = GenerateSharedFrameworkProject(c, SharedFrameworkTemplateSourceRoot, sharedFrameworkRid);
@ -524,7 +521,7 @@ namespace Microsoft.DotNet.Cli.Build
// Generate RID fallback graph // Generate RID fallback graph
string runtimeGraphGeneratorRuntime = null; string runtimeGraphGeneratorRuntime = null;
switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) switch (RuntimeEnvironment.OperatingSystemPlatform)
{ {
case Platform.Windows: case Platform.Windows:
runtimeGraphGeneratorRuntime = "win"; runtimeGraphGeneratorRuntime = "win";
@ -553,7 +550,7 @@ namespace Microsoft.DotNet.Cli.Build
} }
else 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( File.Copy(

View file

@ -4,7 +4,7 @@ using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;

View file

@ -1,12 +1,4 @@
using System; using Microsoft.DotNet.Cli.Build.Framework;
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;
namespace Microsoft.DotNet.Cli.Build namespace Microsoft.DotNet.Cli.Build
{ {

View file

@ -5,7 +5,7 @@ using System.IO.Compression;
using System.Net.Http; using System.Net.Http;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;

View file

@ -4,8 +4,7 @@ using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build 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) // 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>("BuildVersion"); var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
var configuration = c.BuildContext.Get<string>("Configuration"); var configuration = c.BuildContext.Get<string>("Configuration");
var architecture = PlatformServices.Default.Runtime.RuntimeArchitecture; var architecture = RuntimeEnvironment.RuntimeArchitecture;
var env = new Dictionary<string, string>() var env = new Dictionary<string, string>()
{ {
{ "RID", PlatformServices.Default.Runtime.GetRuntimeIdentifier() }, { "RID", RuntimeEnvironment.GetRuntimeIdentifier() },
{ "OSNAME", PlatformServices.Default.Runtime.OperatingSystem }, { "OSNAME", RuntimeEnvironment.OperatingSystem },
{ "TFM", "dnxcore50" }, { "TFM", "dnxcore50" },
{ "REPOROOT", Dirs.RepoRoot }, { "REPOROOT", Dirs.RepoRoot },
{ "OutputDir", Dirs.Output }, { "OutputDir", Dirs.Output },

View file

@ -4,7 +4,7 @@ using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;

View file

@ -7,8 +7,7 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using static Microsoft.DotNet.Cli.Build.FS; 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))] [Target(nameof(GenerateVersions), nameof(UpdateTemplateVersions), nameof(CheckPrereqs), nameof(LocateStage0), nameof(ExpectedBuildArtifacts))]
public static BuildTargetResult Init(BuildTargetContext c) public static BuildTargetResult Init(BuildTargetContext c)
{ {
var runtimeInfo = PlatformServices.Default.Runtime;
var configEnv = Environment.GetEnvironmentVariable("CONFIGURATION"); var configEnv = Environment.GetEnvironmentVariable("CONFIGURATION");
if (string.IsNullOrEmpty(configEnv)) if (string.IsNullOrEmpty(configEnv))
@ -51,8 +48,8 @@ namespace Microsoft.DotNet.Cli.Build
c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}"); c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}");
c.Info("Build Environment:"); c.Info("Build Environment:");
c.Info($" Operating System: {runtimeInfo.OperatingSystem} {runtimeInfo.OperatingSystemVersion}"); c.Info($" Operating System: {RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}");
c.Info($" Platform: {runtimeInfo.OperatingSystemPlatform}"); c.Info($" Platform: {RuntimeEnvironment.OperatingSystemPlatform}");
return c.Success(); return c.Success();
} }

View file

@ -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 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 namespace Microsoft.DotNet.Cli.Build
{ {
public static class TestPackageProjects public static class TestPackageProjects

View file

@ -2,10 +2,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build namespace Microsoft.DotNet.Cli.Build
@ -28,7 +26,7 @@ namespace Microsoft.DotNet.Cli.Build
private string GetCrossgenPathForVersion() private string GetCrossgenPathForVersion()
{ {
string arch = PlatformServices.Default.Runtime.RuntimeArchitecture; string arch = RuntimeEnvironment.RuntimeArchitecture;
string packageId; string packageId;
if (CurrentPlatform.IsWindows) if (CurrentPlatform.IsWindows)
{ {

View file

@ -1,7 +1,7 @@
using Microsoft.Extensions.PlatformAbstractions; using System;
using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Build namespace Microsoft.DotNet.Cli.Build
{ {
@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Cli.Build
public static readonly string Output = Path.Combine( public static readonly string Output = Path.Combine(
RepoRoot, RepoRoot,
"artifacts", "artifacts",
PlatformServices.Default.Runtime.GetRuntimeIdentifier()); RuntimeEnvironment.GetRuntimeIdentifier());
public static readonly string Intermediate = Path.Combine(Output, "intermediate"); public static readonly string Intermediate = Path.Combine(Output, "intermediate");
public static readonly string PackagesIntermediate = Path.Combine(Output, "packages/intermediate"); public static readonly string PackagesIntermediate = Path.Combine(Output, "packages/intermediate");

View file

@ -1,8 +1,8 @@
using Microsoft.DotNet.Cli.Build.Framework; using System.IO;
using Microsoft.Extensions.PlatformAbstractions;
using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Build namespace Microsoft.DotNet.Cli.Build
{ {
@ -43,12 +43,12 @@ namespace Microsoft.DotNet.Cli.Build
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0", return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0",
PlatformServices.Default.Runtime.OperatingSystemPlatform.ToString(), RuntimeEnvironment.OperatingSystemPlatform.ToString(),
PlatformServices.Default.Runtime.RuntimeArchitecture); RuntimeEnvironment.RuntimeArchitecture);
} }
else else
{ {
return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0", PlatformServices.Default.Runtime.OperatingSystemPlatform.ToString()); return Path.Combine(Directory.GetCurrentDirectory(), ".dotnet_stage0", RuntimeEnvironment.OperatingSystemPlatform.ToString());
} }
} }

View file

@ -1,13 +1,4 @@
using System; 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 abstract class AbstractPathBasedCommandResolver : ICommandResolver public abstract class AbstractPathBasedCommandResolver : ICommandResolver

View file

@ -1,24 +1,16 @@
using System; using Microsoft.DotNet.InternalAbstractions;
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 AppBaseCommandResolver : AbstractPathBasedCommandResolver public class AppBaseCommandResolver : AbstractPathBasedCommandResolver
{ {
public AppBaseCommandResolver(IEnvironmentProvider environment, public AppBaseCommandResolver(IEnvironmentProvider environment,
IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { } IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { }
internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments) internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments)
{ {
return _environment.GetCommandPathFromRootPath( return _environment.GetCommandPathFromRootPath(
PlatformServices.Default.Application.ApplicationBasePath, ApplicationEnvironment.ApplicationBasePath,
commandResolverArguments.CommandName); commandResolverArguments.CommandName);
} }

View file

@ -1,7 +1,7 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {
@ -15,7 +15,7 @@ namespace Microsoft.DotNet.Cli.Utils
} }
if (commandResolverArguments.CommandName.EndsWith(FileNameSuffixes.DotNet.DynamicLib)) if (commandResolverArguments.CommandName.EndsWith(FileNameSuffixes.DotNet.DynamicLib))
{ {
var localPath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, var localPath = Path.Combine(ApplicationEnvironment.ApplicationBasePath,
commandResolverArguments.CommandName); commandResolverArguments.CommandName);
if (File.Exists(localPath)) if (File.Exists(localPath))
{ {

View file

@ -1,13 +1,4 @@
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 namespace Microsoft.DotNet.Cli.Utils
{ {
@ -15,9 +6,9 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
private IList<ICommandResolver> _orderedCommandResolvers; private IList<ICommandResolver> _orderedCommandResolvers;
public IEnumerable<ICommandResolver> OrderedCommandResolvers public IEnumerable<ICommandResolver> OrderedCommandResolvers
{ {
get get
{ {
return _orderedCommandResolvers; return _orderedCommandResolvers;
} }
@ -32,7 +23,7 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
_orderedCommandResolvers.Add(commandResolver); _orderedCommandResolvers.Add(commandResolver);
} }
public CommandSpec Resolve(CommandResolverArguments commandResolverArguments) public CommandSpec Resolve(CommandResolverArguments commandResolverArguments)
{ {
foreach (var commandResolver in _orderedCommandResolvers) foreach (var commandResolver in _orderedCommandResolvers)

View file

@ -1,13 +1,4 @@
using System; using Microsoft.DotNet.InternalAbstractions;
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
{ {
@ -19,7 +10,7 @@ namespace Microsoft.DotNet.Cli.Utils
var packagedCommandSpecFactory = new PackagedCommandSpecFactory(); var packagedCommandSpecFactory = new PackagedCommandSpecFactory();
var platformCommandSpecFactory = default(IPlatformCommandSpecFactory); var platformCommandSpecFactory = default(IPlatformCommandSpecFactory);
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{ {
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
} }

View file

@ -2,26 +2,15 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.Extensions.DependencyModel; 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 namespace Microsoft.DotNet.Cli.Utils
{ {
public class DepsJsonCommandResolver : ICommandResolver public class DepsJsonCommandResolver : ICommandResolver
{ {
private static readonly string[] s_extensionPreferenceOrder = new [] private static readonly string[] s_extensionPreferenceOrder = new[]
{ {
"", "",
".exe", ".exe",
".dll" ".dll"
@ -30,7 +19,7 @@ namespace Microsoft.DotNet.Cli.Utils
private string _nugetPackageRoot; private string _nugetPackageRoot;
private Muxer _muxer; private Muxer _muxer;
public DepsJsonCommandResolver(string nugetPackageRoot) public DepsJsonCommandResolver(string nugetPackageRoot)
: this(new Muxer(), nugetPackageRoot) { } : this(new Muxer(), nugetPackageRoot) { }
public DepsJsonCommandResolver(Muxer muxer, string nugetPackageRoot) public DepsJsonCommandResolver(Muxer muxer, string nugetPackageRoot)
@ -46,16 +35,16 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
return null; return null;
} }
return ResolveFromDepsJsonFile( return ResolveFromDepsJsonFile(
commandResolverArguments.CommandName, commandResolverArguments.CommandName,
commandResolverArguments.CommandArguments.OrEmptyIfNull(), commandResolverArguments.CommandArguments.OrEmptyIfNull(),
commandResolverArguments.DepsJsonFile); commandResolverArguments.DepsJsonFile);
} }
private CommandSpec ResolveFromDepsJsonFile( private CommandSpec ResolveFromDepsJsonFile(
string commandName, string commandName,
IEnumerable<string> commandArgs, IEnumerable<string> commandArgs,
string depsJsonFile) string depsJsonFile)
{ {
var dependencyContext = LoadDependencyContextFromFile(depsJsonFile); var dependencyContext = LoadDependencyContextFromFile(depsJsonFile);
@ -67,8 +56,8 @@ namespace Microsoft.DotNet.Cli.Utils
} }
return CreateCommandSpecUsingMuxerIfPortable( return CreateCommandSpecUsingMuxerIfPortable(
commandPath, commandPath,
commandArgs, commandArgs,
depsJsonFile, depsJsonFile,
CommandResolutionStrategy.DepsFile, CommandResolutionStrategy.DepsFile,
_nugetPackageRoot, _nugetPackageRoot,
@ -93,11 +82,11 @@ namespace Microsoft.DotNet.Cli.Utils
var commandCandidates = new List<CommandCandidate>(); var commandCandidates = new List<CommandCandidate>();
var assemblyCommandCandidates = GetCommandCandidates( var assemblyCommandCandidates = GetCommandCandidates(
commandName, commandName,
dependencyContext, dependencyContext,
CommandCandidateType.RuntimeCommandCandidate); CommandCandidateType.RuntimeCommandCandidate);
var nativeCommandCandidates = GetCommandCandidates( var nativeCommandCandidates = GetCommandCandidates(
commandName, commandName,
dependencyContext, dependencyContext,
CommandCandidateType.NativeCommandCandidate); CommandCandidateType.NativeCommandCandidate);
@ -110,7 +99,7 @@ namespace Microsoft.DotNet.Cli.Utils
} }
private IEnumerable<CommandCandidate> GetCommandCandidates( private IEnumerable<CommandCandidate> GetCommandCandidates(
string commandName, string commandName,
DependencyContext dependencyContext, DependencyContext dependencyContext,
CommandCandidateType commandCandidateType) CommandCandidateType commandCandidateType)
{ {
@ -133,7 +122,7 @@ namespace Microsoft.DotNet.Cli.Utils
commandName, commandName,
runtimeAssetGroups, runtimeAssetGroups,
runtimeLibrary.Name, runtimeLibrary.Name,
runtimeLibrary.Version)); runtimeLibrary.Version));
} }
return commandCandidates; return commandCandidates;
@ -141,14 +130,14 @@ namespace Microsoft.DotNet.Cli.Utils
private IEnumerable<CommandCandidate> GetCommandCandidatesFromRuntimeAssetGroups( private IEnumerable<CommandCandidate> GetCommandCandidatesFromRuntimeAssetGroups(
string commandName, string commandName,
IEnumerable<RuntimeAssetGroup> runtimeAssetGroups, IEnumerable<RuntimeAssetGroup> runtimeAssetGroups,
string PackageName, string PackageName,
string PackageVersion) string PackageVersion)
{ {
var candidateAssetGroups = runtimeAssetGroups var candidateAssetGroups = runtimeAssetGroups
.Where(r => r.Runtime == string.Empty) .Where(r => r.Runtime == string.Empty)
.Where(a => .Where(a =>
a.AssetPaths.Any(p => a.AssetPaths.Any(p =>
Path.GetFileNameWithoutExtension(p).Equals(commandName, StringComparison.OrdinalIgnoreCase))); Path.GetFileNameWithoutExtension(p).Equals(commandName, StringComparison.OrdinalIgnoreCase)));
var commandCandidates = new List<CommandCandidate>(); var commandCandidates = new List<CommandCandidate>();
@ -190,9 +179,9 @@ namespace Microsoft.DotNet.Cli.Utils
} }
private CommandSpec CreateCommandSpecUsingMuxerIfPortable( private CommandSpec CreateCommandSpecUsingMuxerIfPortable(
string commandPath, string commandPath,
IEnumerable<string> commandArgs, IEnumerable<string> commandArgs,
string depsJsonFile, string depsJsonFile,
CommandResolutionStrategy commandResolutionStrategy, CommandResolutionStrategy commandResolutionStrategy,
string nugetPackagesRoot, string nugetPackagesRoot,
bool isPortable) bool isPortable)
@ -248,9 +237,9 @@ namespace Microsoft.DotNet.Cli.Utils
public string GetAbsoluteCommandPath(string nugetPackageRoot) public string GetAbsoluteCommandPath(string nugetPackageRoot)
{ {
return Path.Combine( return Path.Combine(
nugetPackageRoot.Replace('/', Path.DirectorySeparatorChar), nugetPackageRoot.Replace('/', Path.DirectorySeparatorChar),
PackageName.Replace('/', Path.DirectorySeparatorChar), PackageName.Replace('/', Path.DirectorySeparatorChar),
PackageVersion.Replace('/', Path.DirectorySeparatorChar), PackageVersion.Replace('/', Path.DirectorySeparatorChar),
RelativeCommandPath.Replace('/', Path.DirectorySeparatorChar)); RelativeCommandPath.Replace('/', Path.DirectorySeparatorChar));
} }
} }

View file

@ -1,13 +1,4 @@
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 namespace Microsoft.DotNet.Cli.Utils
{ {

View file

@ -1,13 +1,4 @@
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 namespace Microsoft.DotNet.Cli.Utils
{ {

View file

@ -1,13 +1,8 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using Microsoft.DotNet.InternalAbstractions;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {
@ -78,7 +73,7 @@ namespace Microsoft.DotNet.Cli.Utils
var projectContext = ProjectContext.Create( var projectContext = ProjectContext.Create(
projectRootPath, projectRootPath,
framework, framework,
PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
if (projectContext.RuntimeIdentifier == null) if (projectContext.RuntimeIdentifier == null)
{ {

View file

@ -1,19 +1,8 @@
using System; namespace Microsoft.DotNet.Cli.Utils
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 class PathCommandResolver : AbstractPathBasedCommandResolver public class PathCommandResolver : AbstractPathBasedCommandResolver
{ {
public PathCommandResolver(IEnvironmentProvider environment, public PathCommandResolver(IEnvironmentProvider environment,
IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { } IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { }
internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments) internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments)

View file

@ -2,9 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
@ -128,7 +128,7 @@ namespace Microsoft.DotNet.Cli.Utils
return ProjectContext.Create( return ProjectContext.Create(
projectRootPath, projectRootPath,
framework, framework,
PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
} }

View file

@ -1,19 +1,8 @@
using System; namespace Microsoft.DotNet.Cli.Utils
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 class ProjectPathCommandResolver : AbstractPathBasedCommandResolver public class ProjectPathCommandResolver : AbstractPathBasedCommandResolver
{ {
public ProjectPathCommandResolver(IEnvironmentProvider environment, public ProjectPathCommandResolver(IEnvironmentProvider environment,
IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { } IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { }
internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments) internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments)
@ -24,7 +13,7 @@ namespace Microsoft.DotNet.Cli.Utils
} }
return _environment.GetCommandPathFromRootPath( return _environment.GetCommandPathFromRootPath(
commandResolverArguments.ProjectDirectory, commandResolverArguments.ProjectDirectory,
commandResolverArguments.CommandName, commandResolverArguments.CommandName,
commandResolverArguments.InferredExtensions.OrEmptyIfNull()); commandResolverArguments.InferredExtensions.OrEmptyIfNull());
} }

View file

@ -2,29 +2,24 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.DependencyModel;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
using NuGet.Packaging;
using NuGet.ProjectModel;
using LockFile = Microsoft.DotNet.ProjectModel.Graph.LockFile;
using FileFormatException = Microsoft.DotNet.ProjectModel.FileFormatException; using FileFormatException = Microsoft.DotNet.ProjectModel.FileFormatException;
using LockFile = Microsoft.DotNet.ProjectModel.Graph.LockFile;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {
public class ProjectToolsCommandResolver : ICommandResolver public class ProjectToolsCommandResolver : ICommandResolver
{ {
private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetCoreApp10; private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetCoreApp10;
private static readonly CommandResolutionStrategy s_commandResolutionStrategy = private static readonly CommandResolutionStrategy s_commandResolutionStrategy =
CommandResolutionStrategy.ProjectToolsPackage; CommandResolutionStrategy.ProjectToolsPackage;
private static readonly string s_currentRuntimeIdentifier = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); private static readonly string s_currentRuntimeIdentifier = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier();
private List<string> _allowedCommandExtensions; private List<string> _allowedCommandExtensions;
@ -34,7 +29,7 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
_packagedCommandSpecFactory = packagedCommandSpecFactory; _packagedCommandSpecFactory = packagedCommandSpecFactory;
_allowedCommandExtensions = new List<string>() _allowedCommandExtensions = new List<string>()
{ {
FileNameSuffixes.DotNet.DynamicLib FileNameSuffixes.DotNet.DynamicLib
}; };
@ -47,15 +42,15 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
return null; return null;
} }
return ResolveFromProjectTools( return ResolveFromProjectTools(
commandResolverArguments.CommandName, commandResolverArguments.CommandName,
commandResolverArguments.CommandArguments.OrEmptyIfNull(), commandResolverArguments.CommandArguments.OrEmptyIfNull(),
commandResolverArguments.ProjectDirectory); commandResolverArguments.ProjectDirectory);
} }
private CommandSpec ResolveFromProjectTools( private CommandSpec ResolveFromProjectTools(
string commandName, string commandName,
IEnumerable<string> args, IEnumerable<string> args,
string projectDirectory) string projectDirectory)
{ {
@ -70,7 +65,7 @@ namespace Microsoft.DotNet.Cli.Utils
return ResolveCommandSpecFromAllToolLibraries( return ResolveCommandSpecFromAllToolLibraries(
toolsLibraries, toolsLibraries,
commandName, commandName,
args, args,
projectContext); projectContext);
} }
@ -101,7 +96,7 @@ namespace Microsoft.DotNet.Cli.Utils
ProjectContext projectContext) ProjectContext projectContext)
{ {
var nugetPackagesRoot = projectContext.PackagesDirectory; var nugetPackagesRoot = projectContext.PackagesDirectory;
var lockFile = GetToolLockFile(toolLibraryRange, nugetPackagesRoot); var lockFile = GetToolLockFile(toolLibraryRange, nugetPackagesRoot);
var toolLibrary = lockFile.Targets var toolLibrary = lockFile.Targets
@ -112,10 +107,10 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
return null; return null;
} }
var depsFileRoot = Path.GetDirectoryName(lockFile.LockFilePath); var depsFileRoot = Path.GetDirectoryName(lockFile.LockFilePath);
var depsFilePath = GetToolDepsFilePath(toolLibraryRange, lockFile, depsFileRoot); var depsFilePath = GetToolDepsFilePath(toolLibraryRange, lockFile, depsFileRoot);
return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary( return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary(
toolLibrary, toolLibrary,
commandName, commandName,
@ -159,8 +154,8 @@ namespace Microsoft.DotNet.Cli.Utils
var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot); var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot);
return toolPathCalculator.GetBestLockFilePath( return toolPathCalculator.GetBestLockFilePath(
toolLibrary.Name, toolLibrary.Name,
toolLibrary.VersionRange, toolLibrary.VersionRange,
s_toolPackageFramework); s_toolPackageFramework);
} }
@ -182,8 +177,8 @@ namespace Microsoft.DotNet.Cli.Utils
} }
private string GetToolDepsFilePath( private string GetToolDepsFilePath(
LibraryRange toolLibrary, LibraryRange toolLibrary,
LockFile toolLockFile, LockFile toolLockFile,
string depsPathRoot) string depsPathRoot)
{ {
var depsJsonPath = Path.Combine( var depsJsonPath = Path.Combine(
@ -196,7 +191,7 @@ namespace Microsoft.DotNet.Cli.Utils
} }
private void EnsureToolJsonDepsFileExists( private void EnsureToolJsonDepsFileExists(
LockFile toolLockFile, LockFile toolLockFile,
string depsPath) string depsPath)
{ {
if (!File.Exists(depsPath)) if (!File.Exists(depsPath))
@ -207,7 +202,7 @@ namespace Microsoft.DotNet.Cli.Utils
// Need to unit test this, so public // Need to unit test this, so public
public void GenerateDepsJsonFile( public void GenerateDepsJsonFile(
LockFile toolLockFile, LockFile toolLockFile,
string depsPath) string depsPath)
{ {
Reporter.Verbose.WriteLine($"Generating deps.json at: {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 exporter = projectContext.CreateExporter(Constants.DefaultConfiguration);
var dependencyContext = new DependencyContextBuilder() var dependencyContext = new DependencyContextBuilder()
.Build(null, .Build(null,
null, null,
exporter.GetAllExports(), exporter.GetAllExports(),
true, true,
s_toolPackageFramework, s_toolPackageFramework,
string.Empty); string.Empty);
var tempDepsFile = Path.GetTempFileName(); var tempDepsFile = Path.GetTempFileName();
@ -250,7 +245,7 @@ namespace Microsoft.DotNet.Cli.Utils
File.Delete(tempDepsFile); File.Delete(tempDepsFile);
} }
catch (Exception e2) catch (Exception e2)
{ {
Reporter.Verbose.WriteLine($"unable to delete temporary deps.json file: {e2.Message}"); Reporter.Verbose.WriteLine($"unable to delete temporary deps.json file: {e2.Message}");
} }
} }

View file

@ -1,13 +1,4 @@
using System; using System.IO;
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
{ {

View file

@ -1,13 +1,4 @@
using System; using Microsoft.DotNet.InternalAbstractions;
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
{ {
@ -18,7 +9,7 @@ namespace Microsoft.DotNet.Cli.Utils
var environment = new EnvironmentProvider(); var environment = new EnvironmentProvider();
var platformCommandSpecFactory = default(IPlatformCommandSpecFactory); var platformCommandSpecFactory = default(IPlatformCommandSpecFactory);
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{ {
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
} }

View file

@ -2,12 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; 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
{ {
@ -36,7 +30,7 @@ namespace Microsoft.DotNet.Cli.Utils
} }
} }
return useCmdWrapper return useCmdWrapper
? CreateCommandSpecWrappedWithCmd(commandPath, args, resolutionStrategy) ? CreateCommandSpecWrappedWithCmd(commandPath, args, resolutionStrategy)
: CreateCommandSpecFromExecutable(commandPath, args, resolutionStrategy); : CreateCommandSpecFromExecutable(commandPath, args, resolutionStrategy);
} }

View file

@ -1,24 +1,18 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {
internal static class CommandResolver internal static class CommandResolver
{ {
public static CommandSpec TryResolveCommandSpec( public static CommandSpec TryResolveCommandSpec(
string commandName, string commandName,
IEnumerable<string> args, IEnumerable<string> args,
NuGetFramework framework = null, NuGetFramework framework = null,
string configuration=Constants.DefaultConfiguration, string configuration = Constants.DefaultConfiguration,
string outputPath=null) string outputPath = null)
{ {
var commandResolverArgs = new CommandResolverArguments var commandResolverArgs = new CommandResolverArguments
{ {
@ -29,16 +23,16 @@ namespace Microsoft.DotNet.Cli.Utils
Configuration = configuration, Configuration = configuration,
OutputPath = outputPath OutputPath = outputPath
}; };
var defaultCommandResolver = DefaultCommandResolverPolicy.Create(); var defaultCommandResolver = DefaultCommandResolverPolicy.Create();
return defaultCommandResolver.Resolve(commandResolverArgs); return defaultCommandResolver.Resolve(commandResolverArgs);
} }
public static CommandSpec TryResolveScriptCommandSpec( public static CommandSpec TryResolveScriptCommandSpec(
string commandName, string commandName,
IEnumerable<string> args, IEnumerable<string> args,
Project project, Project project,
string[] inferredExtensionList) string[] inferredExtensionList)
{ {
var commandResolverArgs = new CommandResolverArguments var commandResolverArgs = new CommandResolverArguments
@ -50,7 +44,7 @@ namespace Microsoft.DotNet.Cli.Utils
}; };
var scriptCommandResolver = ScriptCommandResolverPolicy.Create(); var scriptCommandResolver = ScriptCommandResolverPolicy.Create();
return scriptCommandResolver.Resolve(commandResolverArgs); return scriptCommandResolver.Resolve(commandResolverArgs);
} }
} }

View file

@ -1,13 +1,13 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // 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 namespace Microsoft.DotNet.Cli.Utils
{ {
public static class Constants public static class Constants
{ {
private static Platform CurrentPlatform => PlatformServices.Default.Runtime.OperatingSystemPlatform; private static Platform CurrentPlatform => RuntimeEnvironment.OperatingSystemPlatform;
public const string DefaultConfiguration = "Debug"; public const string DefaultConfiguration = "Debug";
public static readonly string ProjectFileName = "project.json"; public static readonly string ProjectFileName = "project.json";

View file

@ -1,7 +1,5 @@
using System; using System;
using System.IO; using System.IO;
using System.Reflection;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {

View file

@ -4,7 +4,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {
@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
var content = File.ReadAllText(DotnetFiles.VersionFile); var content = File.ReadAllText(DotnetFiles.VersionFile);
content += Environment.NewLine; content += Environment.NewLine;
content += PlatformServices.Default.Runtime.GetRuntimeIdentifier(); content += RuntimeEnvironment.GetRuntimeIdentifier();
return content; return content;
} }
} }

View file

@ -1,9 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {

View file

@ -2,8 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {
@ -19,7 +18,7 @@ namespace Microsoft.DotNet.Cli.Utils
if (_executableExtensions == null) if (_executableExtensions == null)
{ {
_executableExtensions = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows _executableExtensions = RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows
? Environment.GetEnvironmentVariable("PATHEXT") ? Environment.GetEnvironmentVariable("PATHEXT")
.Split(';') .Split(';')
.Select(e => e.ToLower().Trim('"')) .Select(e => e.ToLower().Trim('"'))
@ -36,7 +35,7 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
if (_searchPaths == null) if (_searchPaths == null)
{ {
var searchPaths = new List<string> { PlatformServices.Default.Application.ApplicationBasePath }; var searchPaths = new List<string> { ApplicationEnvironment.ApplicationBasePath };
searchPaths.AddRange(Environment searchPaths.AddRange(Environment
.GetEnvironmentVariable("PATH") .GetEnvironmentVariable("PATH")

View file

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {

View file

@ -1,7 +1,5 @@
using System; using System;
using System.IO; using System.IO;
using Microsoft.Extensions.PlatformAbstractions;
using System.Diagnostics;
using System.Reflection; using System.Reflection;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils

View file

@ -3,7 +3,7 @@
using System; using System;
using System.IO; using System.IO;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Tools.Common namespace Microsoft.DotNet.Tools.Common
{ {
@ -98,7 +98,7 @@ namespace Microsoft.DotNet.Tools.Common
} }
StringComparison compare; StringComparison compare;
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{ {
compare = StringComparison.OrdinalIgnoreCase; compare = StringComparison.OrdinalIgnoreCase;
// check if paths are on the same volume // check if paths are on the same volume
@ -216,7 +216,7 @@ namespace Microsoft.DotNet.Tools.Common
{ {
var comparison = StringComparison.Ordinal; var comparison = StringComparison.Ordinal;
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{ {
comparison = StringComparison.OrdinalIgnoreCase; comparison = StringComparison.OrdinalIgnoreCase;
} }

View file

@ -2,7 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
@ -100,7 +100,7 @@ namespace Microsoft.DotNet.Cli.Utils
if (framework.IsDesktop()) if (framework.IsDesktop())
{ {
IPlatformCommandSpecFactory platformCommandSpecFactory = null; IPlatformCommandSpecFactory platformCommandSpecFactory = null;
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{ {
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
} }

View file

@ -1,9 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // 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 namespace Microsoft.DotNet.Cli.Utils
{ {
// Stupid-simple console manager // Stupid-simple console manager

View file

@ -1,10 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.Utils.CommandParsing; using Microsoft.DotNet.Cli.Utils.CommandParsing;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {
@ -48,7 +47,7 @@ namespace Microsoft.DotNet.Cli.Utils
private static string[] DetermineInferredScriptExtensions() private static string[] DetermineInferredScriptExtensions()
{ {
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{ {
return new string[] { "", ".cmd" }; return new string[] { "", ".cmd" };
} }

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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

View file

@ -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;
}
}
}
}
}

View file

@ -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> _platform = new Lazy<Platform>(DetermineOSPlatform);
private static readonly Lazy<DistroInfo> _distroInfo = new Lazy<DistroInfo>(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
}
}

View file

@ -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
}
}

View file

@ -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";
}
}
}
}

View file

@ -7,14 +7,23 @@
}, },
"compilationOptions": { "compilationOptions": {
"warningsAsErrors": true, "warningsAsErrors": true,
"keyFile": "../../tools/Key.snk" "keyFile": "../../tools/Key.snk",
}, "allowUnsafe": true
"dependencies": {
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-20581"
}, },
"frameworks": { "frameworks": {
"net451": {}, "net451": { },
"netstandard1.3": {} "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": { }
} }

View file

@ -12,9 +12,9 @@ using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text;
using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.DotNet.ProjectModel.Files; using Microsoft.DotNet.ProjectModel.Files;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.ProjectModel.Workspaces namespace Microsoft.DotNet.ProjectModel.Workspaces
@ -225,7 +225,7 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces
{ {
keyFile = Path.GetFullPath(Path.Combine(projectDirectory, compilerOptions.KeyFile)); 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( return options.WithCryptoPublicKey(
SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile))); SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile)));

View file

@ -1,5 +1,5 @@
using System; using System;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.ProjectModel namespace Microsoft.DotNet.ProjectModel
{ {
@ -13,7 +13,7 @@ namespace Microsoft.DotNet.ProjectModel
{ {
get get
{ {
switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) switch (RuntimeEnvironment.OperatingSystemPlatform)
{ {
case Platform.Windows: case Platform.Windows:
return Windows; return Windows;

View file

@ -6,10 +6,10 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Resolution; using Microsoft.DotNet.ProjectModel.Resolution;
using Microsoft.Extensions.Internal; using Microsoft.Extensions.Internal;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.ProjectModel namespace Microsoft.DotNet.ProjectModel
@ -267,7 +267,7 @@ namespace Microsoft.DotNet.ProjectModel
{ {
// we got a ridless target for desktop so turning portable mode on // we got a ridless target for desktop so turning portable mode on
isPortable = true; isPortable = true;
var legacyRuntime = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); var legacyRuntime = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier();
if (RuntimeIdentifiers.Contains(legacyRuntime)) if (RuntimeIdentifiers.Contains(legacyRuntime))
{ {
runtime = legacyRuntime; runtime = legacyRuntime;

View file

@ -7,11 +7,10 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel.Utilities; using Microsoft.DotNet.ProjectModel.Utilities;
using Microsoft.Extensions.DependencyModel.Resolution; using Microsoft.Extensions.DependencyModel.Resolution;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.ProjectModel.Resolution namespace Microsoft.DotNet.ProjectModel.Resolution
@ -63,7 +62,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
return referenceAssembliesPath; return referenceAssembliesPath;
} }
if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{ {
// There is no reference assemblies path outside of windows // There is no reference assemblies path outside of windows
// The environment variable can be used to specify one // 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) private static FrameworkInformation GetFrameworkInformation(NuGetFramework targetFramework, string referenceAssembliesPath)
{ {
// Check for legacy frameworks // Check for legacy frameworks
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows && if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows &&
targetFramework.IsDesktop() && targetFramework.IsDesktop() &&
targetFramework.Version <= new Version(3, 5, 0, 0)) targetFramework.Version <= new Version(3, 5, 0, 0))
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.Extensions.PlatformAbstractions namespace Microsoft.DotNet.InternalAbstractions
{ {
// This is to support some legacy stuff. // This is to support some legacy stuff.
// dnu restore (and thus dotnet restore) always uses win7-x64 as the Windows restore target, // 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 public static class RuntimeEnvironmentRidExtensions
{ {
// Work around NuGet/Home#1941 // Work around NuGet/Home#1941
public static IEnumerable<string> GetOverrideRestoreRuntimeIdentifiers(this IRuntimeEnvironment env) public static IEnumerable<string> GetOverrideRestoreRuntimeIdentifiers()
{ {
if (env.OperatingSystemPlatform != Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{ {
yield return env.GetRuntimeIdentifier(); yield return RuntimeEnvironment.GetRuntimeIdentifier();
} }
else 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) // 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 else
{ {
var arch = env.RuntimeArchitecture.ToLowerInvariant(); var arch = RuntimeEnvironment.RuntimeArchitecture.ToLowerInvariant();
return "win7-" + arch; return "win7-" + arch;
} }
} }
public static IEnumerable<string> GetAllCandidateRuntimeIdentifiers(this IRuntimeEnvironment env) public static IEnumerable<string> GetAllCandidateRuntimeIdentifiers()
{ {
if (env.OperatingSystemPlatform != Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{ {
yield return env.GetRuntimeIdentifier(); yield return RuntimeEnvironment.GetRuntimeIdentifier();
} }
else else
{ {
var arch = env.RuntimeArchitecture.ToLowerInvariant(); var arch = RuntimeEnvironment.RuntimeArchitecture.ToLowerInvariant();
if (env.OperatingSystemVersion.StartsWith("6.1", StringComparison.Ordinal)) if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("6.1", StringComparison.Ordinal))
{ {
yield return "win7-" + arch; 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 "win8-" + arch;
yield return "win7-" + 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 "win81-" + arch;
yield return "win8-" + arch; yield return "win8-" + arch;
yield return "win7-" + 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 "win10-" + arch;
yield return "win81-" + arch; yield return "win81-" + arch;

View file

@ -3,7 +3,7 @@
using System; using System;
using System.IO; using System.IO;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.ProjectModel.Utilities namespace Microsoft.DotNet.ProjectModel.Utilities
{ {
@ -84,7 +84,7 @@ namespace Microsoft.DotNet.ProjectModel.Utilities
} }
StringComparison compare; StringComparison compare;
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{ {
compare = StringComparison.OrdinalIgnoreCase; compare = StringComparison.OrdinalIgnoreCase;
// check if paths are on the same volume // check if paths are on the same volume

View file

@ -2,11 +2,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Extensions.PlatformAbstractions; using System.Reflection;
namespace Microsoft.Extensions.DependencyModel namespace Microsoft.Extensions.DependencyModel
{ {

View file

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.Extensions.PlatformAbstractions;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;

View file

@ -4,8 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection; using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Extensions.EnvironmentAbstractions; using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.Extensions.DependencyModel.Resolution namespace Microsoft.Extensions.DependencyModel.Resolution
@ -25,7 +24,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
} }
internal AppBaseCompilationAssemblyResolver(IFileSystem fileSystem) internal AppBaseCompilationAssemblyResolver(IFileSystem fileSystem)
: this(fileSystem, PlatformServices.Default.Application.ApplicationBasePath) : this(fileSystem, ApplicationEnvironment.ApplicationBasePath)
{ {
} }

View file

@ -1,10 +1,8 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using Microsoft.DotNet.InternalAbstractions;
using System.IO;
using Microsoft.Extensions.EnvironmentAbstractions; using Microsoft.Extensions.EnvironmentAbstractions;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.Extensions.DependencyModel.Resolution namespace Microsoft.Extensions.DependencyModel.Resolution
{ {
@ -12,7 +10,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
{ {
public static readonly string DotNetReferenceAssembliesPathEnv = "DOTNET_REFERENCE_ASSEMBLIES_PATH"; 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); var path = envirnment.GetEnvironmentVariable(DotNetReferenceAssembliesPathEnv);
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))
@ -20,17 +18,17 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
return path; return path;
} }
return GetDefaultDotNetReferenceAssembliesPath(fileSystem, runtimeEnvironment); return GetDefaultDotNetReferenceAssembliesPath(fileSystem);
} }
public static string Resolve() 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) if (os == Platform.Windows)
{ {

View file

@ -4,7 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Extensions.EnvironmentAbstractions; using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.Extensions.DependencyModel.Resolution namespace Microsoft.Extensions.DependencyModel.Resolution
@ -15,7 +15,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
private readonly string _nugetPackageDirectory; private readonly string _nugetPackageDirectory;
public PackageCompilationAssemblyResolver() 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, internal PackageCompilationAssemblyResolver(IEnvironment environment,
IRuntimeEnvironment runtimeEnvironment,
IFileSystem fileSystem) IFileSystem fileSystem)
: this(fileSystem, GetDefaultPackageDirectory(runtimeEnvironment, environment)) : this(fileSystem, GetDefaultPackageDirectory(environment))
{ {
} }
@ -37,7 +36,10 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
_nugetPackageDirectory = nugetPackageDirectory; _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"); var packageDirectory = environment.GetEnvironmentVariable("NUGET_PACKAGES");
@ -47,7 +49,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
} }
string basePath; string basePath;
if (runtimeEnvironment.OperatingSystemPlatform == Platform.Windows) if (osPlatform == Platform.Windows)
{ {
basePath = environment.GetEnvironmentVariable("USERPROFILE"); basePath = environment.GetEnvironmentVariable("USERPROFILE");
} }

View file

@ -4,7 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Extensions.EnvironmentAbstractions; using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.Extensions.DependencyModel.Resolution namespace Microsoft.Extensions.DependencyModel.Resolution
@ -16,7 +16,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
private readonly string[] _fallbackSearchPaths; private readonly string[] _fallbackSearchPaths;
public ReferenceAssemblyPathResolver() 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, : this(fileSystem,
GetDefaultReferenceAssembliesPath(runtimeEnvironment, fileSystem, environment), GetDefaultReferenceAssembliesPath(fileSystem, RuntimeEnvironment.OperatingSystemPlatform, environment),
GetFallbackSearchPaths(fileSystem, runtimeEnvironment, environment)) GetFallbackSearchPaths(fileSystem, RuntimeEnvironment.OperatingSystemPlatform, environment))
{ {
} }
@ -85,9 +85,9 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
return false; 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]; return new string[0];
} }
@ -101,16 +101,16 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
return new[] { net20Dir }; 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 // 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)) if (!string.IsNullOrEmpty(referenceAssembliesPath))
{ {
return referenceAssembliesPath; return referenceAssembliesPath;
} }
if (runtimeEnvironment.OperatingSystemPlatform != Platform.Windows) if (platform != Platform.Windows)
{ {
// There is no reference assemblies path outside of windows // There is no reference assemblies path outside of windows
// The environment variable can be used to specify one // The environment variable can be used to specify one

View file

@ -26,7 +26,8 @@
"imports": "portable-net45+wp80+win8+wpa81+dnxcore50", "imports": "portable-net45+wp80+win8+wpa81+dnxcore50",
"dependencies": { "dependencies": {
"System.Diagnostics.Debug": "4.0.11-rc2-24027", "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"
} }
} }
}, },

View file

@ -14,6 +14,7 @@
"Newtonsoft.Json": "7.0.1", "Newtonsoft.Json": "7.0.1",
"Microsoft.DotNet.ProjectModel": "1.0.0-*", "Microsoft.DotNet.ProjectModel": "1.0.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc2-20581", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc2-20581",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-20581",
"Microsoft.DiaSymReader": "1.0.6", "Microsoft.DiaSymReader": "1.0.6",
"Microsoft.DiaSymReader.Native": "1.3.3" "Microsoft.DiaSymReader.Native": "1.3.3"
}, },

View file

@ -7,6 +7,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel.Server; using Microsoft.DotNet.ProjectModel.Server;
using Microsoft.DotNet.Tools.Build; using Microsoft.DotNet.Tools.Build;
using Microsoft.DotNet.Tools.Compiler; using Microsoft.DotNet.Tools.Compiler;
@ -17,7 +18,6 @@ using Microsoft.DotNet.Tools.Publish;
using Microsoft.DotNet.Tools.Restore; using Microsoft.DotNet.Tools.Restore;
using Microsoft.DotNet.Tools.Run; using Microsoft.DotNet.Tools.Run;
using Microsoft.DotNet.Tools.Test; using Microsoft.DotNet.Tools.Test;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.Cli namespace Microsoft.DotNet.Cli
@ -186,12 +186,11 @@ namespace Microsoft.DotNet.Cli
Reporter.Output.WriteLine($" Version: {Product.Version}"); Reporter.Output.WriteLine($" Version: {Product.Version}");
Reporter.Output.WriteLine($" Commit Sha: {commitSha}"); Reporter.Output.WriteLine($" Commit Sha: {commitSha}");
Reporter.Output.WriteLine(); Reporter.Output.WriteLine();
var runtimeEnvironment = PlatformServices.Default.Runtime;
Reporter.Output.WriteLine("Runtime Environment:"); Reporter.Output.WriteLine("Runtime Environment:");
Reporter.Output.WriteLine($" OS Name: {runtimeEnvironment.OperatingSystem}"); Reporter.Output.WriteLine($" OS Name: {RuntimeEnvironment.OperatingSystem}");
Reporter.Output.WriteLine($" OS Version: {runtimeEnvironment.OperatingSystemVersion}"); Reporter.Output.WriteLine($" OS Version: {RuntimeEnvironment.OperatingSystemVersion}");
Reporter.Output.WriteLine($" OS Platform: {runtimeEnvironment.OperatingSystemPlatform}"); Reporter.Output.WriteLine($" OS Platform: {RuntimeEnvironment.OperatingSystemPlatform}");
Reporter.Output.WriteLine($" RID: {runtimeEnvironment.GetRuntimeIdentifier()}"); Reporter.Output.WriteLine($" RID: {RuntimeEnvironment.GetRuntimeIdentifier()}");
} }
private static bool IsArg(string candidate, string longName) private static bool IsArg(string candidate, string longName)

View file

@ -1,9 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
using System.Diagnostics;
namespace Microsoft.DotNet.Cli namespace Microsoft.DotNet.Cli
{ {
@ -41,13 +41,13 @@ namespace Microsoft.DotNet.Cli
_client.InstrumentationKey = InstrumentationKey; _client.InstrumentationKey = InstrumentationKey;
_client.Context.Session.Id = Guid.NewGuid().ToString(); _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<string, string>(); _commonProperties = new Dictionary<string, string>();
_commonProperties.Add(OSVersion, runtimeEnvironment.OperatingSystemVersion); _commonProperties.Add(OSVersion, RuntimeEnvironment.OperatingSystemVersion);
_commonProperties.Add(OSPlatform, runtimeEnvironment.OperatingSystemPlatform.ToString()); _commonProperties.Add(OSPlatform, RuntimeEnvironment.OperatingSystemPlatform.ToString());
_commonProperties.Add(RuntimeId, runtimeEnvironment.GetRuntimeIdentifier()); _commonProperties.Add(RuntimeId, RuntimeEnvironment.GetRuntimeIdentifier());
_commonProperties.Add(ProductVersion, Product.Version); _commonProperties.Add(ProductVersion, Product.Version);
_commonMeasurements = new Dictionary<string, double>(); _commonMeasurements = new Dictionary<string, double>();
} }

View file

@ -4,8 +4,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
// This class is responsible with defining the arguments for the Compile verb. // This class is responsible with defining the arguments for the Compile verb.
@ -121,7 +121,7 @@ namespace Microsoft.DotNet.Tools.Compiler
IEnumerable<NuGetFramework> frameworks = null; IEnumerable<NuGetFramework> frameworks = null;
if (_frameworkOption.HasValue()) if (_frameworkOption.HasValue())
{ {
frameworks = new [] { NuGetFramework.Parse(_frameworkOption.Value()) }; frameworks = new[] { NuGetFramework.Parse(_frameworkOption.Value()) };
} }
var success = execute(files, frameworks, this); var success = execute(files, frameworks, this);
@ -136,7 +136,7 @@ namespace Microsoft.DotNet.Tools.Compiler
var rids = new List<string>(); var rids = new List<string>();
if (string.IsNullOrEmpty(RuntimeValue)) if (string.IsNullOrEmpty(RuntimeValue))
{ {
return PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers(); return RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers();
} }
else else
{ {

View file

@ -2,15 +2,12 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Compiler; using Microsoft.DotNet.Tools.Compiler;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Tools.Build namespace Microsoft.DotNet.Tools.Build
{ {
@ -23,7 +20,7 @@ namespace Microsoft.DotNet.Tools.Build
private readonly DotNetCommandFactory _commandFactory; private readonly DotNetCommandFactory _commandFactory;
private readonly IncrementalManager _incrementalManager; private readonly IncrementalManager _incrementalManager;
public DotNetProjectBuilder(BuildCommandApp args): base(args.ShouldSkipDependencies) public DotNetProjectBuilder(BuildCommandApp args) : base(args.ShouldSkipDependencies)
{ {
_args = args; _args = args;

View file

@ -7,12 +7,7 @@ using System.IO;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Utilities;
using Microsoft.DotNet.Tools.Compiler; using Microsoft.DotNet.Tools.Compiler;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.DotNet.ProjectModel.Compilation;
using NuGet.Protocol.Core.Types;
namespace Microsoft.DotNet.Tools.Build namespace Microsoft.DotNet.Tools.Build
{ {

View file

@ -8,13 +8,13 @@ using System.Linq;
using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Files; using Microsoft.DotNet.Files;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.DotNet.ProjectModel.Files; using Microsoft.DotNet.ProjectModel.Files;
using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Utilities; using Microsoft.DotNet.ProjectModel.Utilities;
using Microsoft.DotNet.Tools.Common; using Microsoft.DotNet.Tools.Common;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.Tools.Publish 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)); var runtimeAssetsToCopy = export.RuntimeAssets.Where(a => ShouldCopyExportRuntimeAsset(context, buildOutputPaths, export, a));
runtimeAssetsToCopy.StructuredCopyTo(outputPath, outputPaths.IntermediateOutputDirectoryPath); runtimeAssetsToCopy.StructuredCopyTo(outputPath, outputPaths.IntermediateOutputDirectoryPath);
foreach(var resourceAsset in export.ResourceAssemblies) foreach (var resourceAsset in export.ResourceAssemblies)
{ {
var dir = Path.Combine(outputPath, resourceAsset.Locale); var dir = Path.Combine(outputPath, resourceAsset.Locale);
if(!Directory.Exists(dir)) if (!Directory.Exists(dir))
{ {
Directory.CreateDirectory(dir); Directory.CreateDirectory(dir);
} }
@ -291,7 +291,7 @@ namespace Microsoft.DotNet.Tools.Publish
foreach (var dependency in dependencies) foreach (var dependency in dependencies)
{ {
var export = exports[dependency.Name]; 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); exclusionList.Add(export.Library.Identity.Name);
CollectDependencies(exports, export.Library.Dependencies, exclusionList); CollectDependencies(exports, export.Library.Dependencies, exclusionList);
@ -454,7 +454,7 @@ namespace Microsoft.DotNet.Tools.Publish
contexts.Where(c => Equals(c.TargetFramework, framework)); contexts.Where(c => Equals(c.TargetFramework, framework));
var rids = string.IsNullOrEmpty(runtime) ? var rids = string.IsNullOrEmpty(runtime) ?
PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers() : RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers() :
new[] { runtime }; new[] { runtime };
return contexts.Select(c => Workspace.GetRuntimeContext(c, rids)); return contexts.Select(c => Workspace.GetRuntimeContext(c, rids));

View file

@ -5,13 +5,13 @@ using System;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Tools.Restore namespace Microsoft.DotNet.Tools.Restore
{ {
public partial class RestoreCommand 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) public static int Run(string[] args)
{ {
@ -28,7 +28,7 @@ namespace Microsoft.DotNet.Tools.Restore
// "--verbosity" switch that goes BEFORE the command // "--verbosity" switch that goes BEFORE the command
var quiet = args.Any(s => s.Equals("--quiet", StringComparison.OrdinalIgnoreCase)); var quiet = args.Any(s => s.Equals("--quiet", StringComparison.OrdinalIgnoreCase));
args = args.Where(s => !s.Equals("--quiet", StringComparison.OrdinalIgnoreCase)).ToArray(); args = args.Where(s => !s.Equals("--quiet", StringComparison.OrdinalIgnoreCase)).ToArray();
app.OnExecute(() => app.OnExecute(() =>
{ {
try try

View file

@ -7,8 +7,8 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
namespace Microsoft.DotNet.Tools.Run namespace Microsoft.DotNet.Tools.Run
@ -70,7 +70,7 @@ namespace Microsoft.DotNet.Tools.Run
var frameworkContexts = _workspace.GetProjectContextCollection(Project).FrameworkOnlyContexts; var frameworkContexts = _workspace.GetProjectContextCollection(Project).FrameworkOnlyContexts;
var rids = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers(); var rids = RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers();
ProjectContext frameworkContext; ProjectContext frameworkContext;
if (Framework == null) if (Framework == null)

View file

@ -6,8 +6,8 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Tools.Test namespace Microsoft.DotNet.Tools.Test
{ {
@ -44,7 +44,7 @@ namespace Microsoft.DotNet.Tools.Test
var projectPath = GetProjectPath(dotnetTestParams.ProjectPath); var projectPath = GetProjectPath(dotnetTestParams.ProjectPath);
var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime) ? var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime) ?
new[] { dotnetTestParams.Runtime } : new[] { dotnetTestParams.Runtime } :
PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers(); RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers();
var exitCode = 0; var exitCode = 0;
// Create a workspace // Create a workspace

View file

@ -11,7 +11,6 @@ using Xunit;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using System.Diagnostics; using System.Diagnostics;
using FluentAssertions; using FluentAssertions;

View file

@ -5,10 +5,9 @@ using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Xunit; using Xunit;
using System.Diagnostics;
namespace Microsoft.DotNet.Tests.EndToEnd namespace Microsoft.DotNet.Tests.EndToEnd
{ {
@ -152,7 +151,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd
.Should() .Should()
.Pass(); .Pass();
} }
[Fact] [Fact]
public void TestDotnetPack() public void TestDotnetPack()
{ {
@ -169,7 +168,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd
var publishCommand = new PublishCommand(TestProject, output: OutputDirectory); var publishCommand = new PublishCommand(TestProject, output: OutputDirectory);
publishCommand.Execute().Should().Pass(); publishCommand.Execute().Should().Pass();
TestExecutable(OutputDirectory, publishCommand.GetPortableOutputName(), s_expectedOutput); TestExecutable(OutputDirectory, publishCommand.GetPortableOutputName(), s_expectedOutput);
} }
[Fact] [Fact]
@ -196,7 +195,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd
TestProject = Path.Combine(TestDirectory, "project.json"); TestProject = Path.Combine(TestDirectory, "project.json");
OutputDirectory = Path.Combine(TestDirectory, s_outputdirName); OutputDirectory = Path.Combine(TestDirectory, s_outputdirName);
Rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); Rid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier();
} }
private static void SetupStaticTestProject() private static void SetupStaticTestProject()
@ -208,7 +207,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd
{ {
Directory.Delete(RestoredTestProjectDirectory, true); Directory.Delete(RestoredTestProjectDirectory, true);
} }
catch(Exception) {} catch (Exception) { }
Directory.CreateDirectory(RestoredTestProjectDirectory); Directory.CreateDirectory(RestoredTestProjectDirectory);
@ -227,7 +226,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd
private bool IsNativeCompilationSupported() private bool IsNativeCompilationSupported()
{ {
bool isSupported = true; bool isSupported = true;
var platform = PlatformServices.Default.Runtime.OperatingSystem.ToLower(); var platform = RuntimeEnvironment.OperatingSystem.ToLower();
switch (platform) switch (platform)
{ {
case "centos": case "centos":

View file

@ -1,21 +1,11 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic; 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 FluentAssertions;
using NuGet.Frameworks; using Microsoft.DotNet.Tools.Test.Utilities;
using Moq;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests namespace Microsoft.DotNet.Cli.Utils.Tests
{ {

View file

@ -1,21 +1,10 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // 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 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 FluentAssertions;
using NuGet.Frameworks; using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests namespace Microsoft.DotNet.Cli.Utils.Tests
{ {

View file

@ -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<IEnvironmentProvider>();
emptyPathEnvironmentMock.Setup(e => e
.GetCommandPath(It.IsAny<string>(), It.IsAny<string[]>()))
.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<IEnvironmentProvider>();
staticPathEnvironmentMock.Setup(e => e
.GetCommandPath(It.IsAny<string>(), It.IsAny<string[]>()))
.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<IEnvironmentProvider>();
staticPathEnvironmentMock.Setup(e => e
.GetCommandPath(It.IsAny<string>(), It.IsAny<string[]>()))
.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<IEnvironmentProvider>();
staticPathEnvironmentMock.Setup(e => e
.GetCommandPath(It.IsAny<string>(), It.IsAny<string[]>()))
.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;
}
}
}

View file

@ -1,22 +1,13 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // 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.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 FluentAssertions;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks; using NuGet.Frameworks;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests namespace Microsoft.DotNet.Cli.Utils.Tests
{ {

View file

@ -2,27 +2,20 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using FluentAssertions;
using System.Text; using Microsoft.DotNet.InternalAbstractions;
using System.Linq;
using Xunit;
using Moq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using System.Threading;
using FluentAssertions;
using NuGet.Frameworks; using NuGet.Frameworks;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests namespace Microsoft.DotNet.Cli.Utils.Tests
{ {
public class GivenAProjectDependenciesCommandResolver public class GivenAProjectDependenciesCommandResolver
{ {
private static readonly string s_liveProjectDirectory = private static readonly string s_liveProjectDirectory =
Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithDirectDependency"); Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithDirectDependency");
[Fact] [Fact]
@ -33,7 +26,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = null, CommandName = null,
CommandArguments = new string[] {""}, CommandArguments = new string[] { "" },
ProjectDirectory = "/some/directory", ProjectDirectory = "/some/directory",
Configuration = "Debug", Configuration = "Debug",
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10 Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
@ -52,7 +45,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "command", CommandName = "command",
CommandArguments = new string[] {""}, CommandArguments = new string[] { "" },
ProjectDirectory = null, ProjectDirectory = null,
Configuration = "Debug", Configuration = "Debug",
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10 Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
@ -71,7 +64,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "command", CommandName = "command",
CommandArguments = new string[] {""}, CommandArguments = new string[] { "" },
ProjectDirectory = s_liveProjectDirectory, ProjectDirectory = s_liveProjectDirectory,
Configuration = "Debug", Configuration = "Debug",
Framework = null Framework = null
@ -90,7 +83,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "command", CommandName = "command",
CommandArguments = new string[] {""}, CommandArguments = new string[] { "" },
ProjectDirectory = s_liveProjectDirectory, ProjectDirectory = s_liveProjectDirectory,
Configuration = null, Configuration = null,
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10 Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
@ -153,7 +146,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "dotnet-hello", CommandName = "dotnet-hello",
CommandArguments = new [] { "arg with space"}, CommandArguments = new[] { "arg with space" },
ProjectDirectory = s_liveProjectDirectory, ProjectDirectory = s_liveProjectDirectory,
Configuration = "Debug", Configuration = "Debug",
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10 Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
@ -203,7 +196,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var projectContext = ProjectContext.Create( var projectContext = ProjectContext.Create(
s_liveProjectDirectory, s_liveProjectDirectory,
FrameworkConstants.CommonFrameworks.NetCoreApp10, FrameworkConstants.CommonFrameworks.NetCoreApp10,
PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
var depsFilePath = var depsFilePath =
projectContext.GetOutputPaths("Debug", outputPath: AppContext.BaseDirectory).RuntimeFiles.DepsJson; projectContext.GetOutputPaths("Debug", outputPath: AppContext.BaseDirectory).RuntimeFiles.DepsJson;
@ -232,7 +225,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var projectContext = ProjectContext.Create( var projectContext = ProjectContext.Create(
s_liveProjectDirectory, s_liveProjectDirectory,
FrameworkConstants.CommonFrameworks.NetCoreApp10, FrameworkConstants.CommonFrameworks.NetCoreApp10,
PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
var depsFilePath = var depsFilePath =
projectContext.GetOutputPaths("Debug", AppContext.BaseDirectory).RuntimeFiles.DepsJson; projectContext.GetOutputPaths("Debug", AppContext.BaseDirectory).RuntimeFiles.DepsJson;
@ -260,7 +253,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments); var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);
result.Should().NotBeNull(); result.Should().NotBeNull();
result.Args.Should().Contain("dotnet-hello"); result.Args.Should().Contain("dotnet-hello");
} }

View file

@ -2,20 +2,11 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using System;
using System.Collections.Generic;
using System.IO; 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 FluentAssertions;
using NuGet.Frameworks; using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests namespace Microsoft.DotNet.Cli.Utils.Tests
{ {
@ -31,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = null, CommandName = null,
CommandArguments = new string[] {""}, CommandArguments = new string[] { "" },
ProjectDirectory = "/some/directory" ProjectDirectory = "/some/directory"
}; };
@ -48,7 +39,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "command", CommandName = "command",
CommandArguments = new string[] {""}, CommandArguments = new string[] { "" },
ProjectDirectory = null ProjectDirectory = null
}; };
@ -130,7 +121,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "projectpathtestcommand1", CommandName = "projectpathtestcommand1",
CommandArguments = new [] { "arg with space"}, CommandArguments = new[] { "arg with space" },
ProjectDirectory = s_testProjectDirectory ProjectDirectory = s_testProjectDirectory
}; };
@ -143,7 +134,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
[Fact] [Fact]
public void It_resolves_commands_with_extensions_defined_in_InferredExtensions() 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); var projectPathCommandResolver = SetupPlatformProjectPathCommandResolver(forceGeneric: true);
foreach (var extension in extensions) foreach (var extension in extensions)
@ -166,7 +157,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandFileName = Path.GetFileName(result.Path); var commandFileName = Path.GetFileName(result.Path);
commandFileName.Should().Be("projectpathexttest" + extension); commandFileName.Should().Be("projectpathexttest" + extension);
} }
} }
[Fact] [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() 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 platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory); var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory);
var testCommandPath = var testCommandPath =
CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "cmdWrapCommand", ".cmd"); CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "cmdWrapCommand", ".cmd");
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
@ -250,7 +241,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
IPlatformCommandSpecFactory platformCommandSpecFactory = new GenericPlatformCommandSpecFactory(); IPlatformCommandSpecFactory platformCommandSpecFactory = new GenericPlatformCommandSpecFactory();
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows
&& !forceGeneric) && !forceGeneric)
{ {
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();

View file

@ -2,27 +2,15 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq; 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 FluentAssertions;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks; using NuGet.Frameworks;
using NuGet.Versioning; using NuGet.Versioning;
using NuGet.ProjectModel; using Xunit;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Compilation;
using NuGet.ProjectModel;
using LockFile = Microsoft.DotNet.ProjectModel.Graph.LockFile;
namespace Microsoft.DotNet.Cli.Utils.Tests 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 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"); Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithToolDependency");
[Fact] [Fact]
@ -41,7 +29,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = null, CommandName = null,
CommandArguments = new string[] {""}, CommandArguments = new string[] { "" },
ProjectDirectory = "/some/directory" ProjectDirectory = "/some/directory"
}; };
@ -58,7 +46,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "command", CommandName = "command",
CommandArguments = new string[] {""}, CommandArguments = new string[] { "" },
ProjectDirectory = null ProjectDirectory = null
}; };
@ -115,7 +103,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "dotnet-portable", CommandName = "dotnet-portable",
CommandArguments = new [] { "arg with space"}, CommandArguments = new[] { "arg with space" },
ProjectDirectory = s_liveProjectDirectory ProjectDirectory = s_liveProjectDirectory
}; };
@ -140,7 +128,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var result = projectToolsCommandResolver.Resolve(commandResolverArguments); var result = projectToolsCommandResolver.Resolve(commandResolverArguments);
result.Should().NotBeNull(); result.Should().NotBeNull();
var commandPath = result.Args.Trim('"'); var commandPath = result.Args.Trim('"');
commandPath.Should().Contain("dotnet-portable.dll"); commandPath.Should().Contain("dotnet-portable.dll");
} }
@ -163,8 +151,8 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot); var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot);
var lockFilePath = toolPathCalculator.GetLockFilePath( var lockFilePath = toolPathCalculator.GetLockFilePath(
"dotnet-portable", "dotnet-portable",
new NuGetVersion("1.0.0"), new NuGetVersion("1.0.0"),
s_toolPackageFramework); s_toolPackageFramework);
var directory = Path.GetDirectoryName(lockFilePath); var directory = Path.GetDirectoryName(lockFilePath);
@ -181,7 +169,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var result = projectToolsCommandResolver.Resolve(commandResolverArguments); var result = projectToolsCommandResolver.Resolve(commandResolverArguments);
result.Should().NotBeNull(); result.Should().NotBeNull();
depsJsonFile = Directory depsJsonFile = Directory
.EnumerateFiles(directory) .EnumerateFiles(directory)
.FirstOrDefault(p => Path.GetFileName(p).EndsWith(FileNameSuffixes.DepsJson)); .FirstOrDefault(p => Path.GetFileName(p).EndsWith(FileNameSuffixes.DepsJson));
@ -198,8 +186,8 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot); var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot);
var lockFilePath = toolPathCalculator.GetLockFilePath( var lockFilePath = toolPathCalculator.GetLockFilePath(
"dotnet-portable", "dotnet-portable",
new NuGetVersion("1.0.0"), new NuGetVersion("1.0.0"),
s_toolPackageFramework); s_toolPackageFramework);
var lockFile = LockFileReader.Read(lockFilePath, designTime: false); var lockFile = LockFileReader.Read(lockFilePath, designTime: false);

View file

@ -1,21 +1,9 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // 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 FluentAssertions;
using NuGet.Frameworks; using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests namespace Microsoft.DotNet.Cli.Utils.Tests
{ {
@ -78,7 +66,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "/some/rooted/path", CommandName = "/some/rooted/path",
CommandArguments = new [] { "arg with space"} CommandArguments = new[] { "arg with space" }
}; };
var result = rootedCommandResolver.Resolve(commandResolverArguments); var result = rootedCommandResolver.Resolve(commandResolverArguments);

View file

@ -1,21 +1,10 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // 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.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 FluentAssertions;
using NuGet.Frameworks; using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests namespace Microsoft.DotNet.Cli.Utils.Tests
{ {
@ -33,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
resolvers.Select(r => r.GetType()) resolvers.Select(r => r.GetType())
.Should() .Should()
.ContainInOrder( .ContainInOrder(
new []{ new[]{
typeof(RootedCommandResolver), typeof(RootedCommandResolver),
typeof(MuxerCommandResolver), typeof(MuxerCommandResolver),
typeof(ProjectPathCommandResolver), typeof(ProjectPathCommandResolver),

View file

@ -2,20 +2,11 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using System;
using System.Collections.Generic;
using System.IO; 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 FluentAssertions;
using NuGet.Frameworks; using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests namespace Microsoft.DotNet.Cli.Utils.Tests
{ {
@ -107,7 +98,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "appbasetestcommand1", CommandName = "appbasetestcommand1",
CommandArguments = new [] { "arg with space"} CommandArguments = new[] { "arg with space" }
}; };
var result = appBaseCommandResolver.Resolve(commandResolverArguments); 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() 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 platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory); var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory);
var testCommandPath = var testCommandPath =
CommandResolverTestUtils.CreateNonRunnableTestCommand(AppContext.BaseDirectory, "cmdWrapCommand", ".cmd"); CommandResolverTestUtils.CreateNonRunnableTestCommand(AppContext.BaseDirectory, "cmdWrapCommand", ".cmd");
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
@ -193,9 +184,9 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{ {
environment = environment ?? new EnvironmentProvider(); 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) && !forceGeneric)
{ {
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();

View file

@ -4,20 +4,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Xunit;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions; using Xunit;
using System.Threading;
namespace StreamForwarderTests namespace StreamForwarderTests
{ {
public class StreamForwarderTests : TestBase 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 static readonly string s_testProjectRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
private TempDirectory _root; private TempDirectory _root;
@ -57,7 +53,7 @@ namespace StreamForwarderTests
[InlineData("123")] [InlineData("123")]
[InlineData("123\n")] [InlineData("123\n")]
public void TestNoForwardingNoCapture(string inputStr) public void TestNoForwardingNoCapture(string inputStr)
{ {
TestCapturingAndForwardingHelper(ForwardOptions.None, inputStr, null, new string[0]); TestCapturingAndForwardingHelper(ForwardOptions.None, inputStr, null, new string[0]);
} }
@ -65,11 +61,11 @@ namespace StreamForwarderTests
[MemberData("ForwardingTheoryVariations")] [MemberData("ForwardingTheoryVariations")]
public void TestForwardingOnly(string inputStr, string[] expectedWrites) 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; expectedWrites[i] += Environment.NewLine;
} }
TestCapturingAndForwardingHelper(ForwardOptions.WriteLine, inputStr, null, expectedWrites); TestCapturingAndForwardingHelper(ForwardOptions.WriteLine, inputStr, null, expectedWrites);
} }
@ -77,13 +73,13 @@ namespace StreamForwarderTests
[MemberData("ForwardingTheoryVariations")] [MemberData("ForwardingTheoryVariations")]
public void TestCaptureOnly(string inputStr, string[] expectedWrites) 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; expectedWrites[i] += Environment.NewLine;
} }
var expectedCaptured = string.Join("", expectedWrites); var expectedCaptured = string.Join("", expectedWrites);
TestCapturingAndForwardingHelper(ForwardOptions.Capture, inputStr, expectedCaptured, new string[0]); TestCapturingAndForwardingHelper(ForwardOptions.Capture, inputStr, expectedCaptured, new string[0]);
} }
@ -91,7 +87,7 @@ namespace StreamForwarderTests
[MemberData("ForwardingTheoryVariations")] [MemberData("ForwardingTheoryVariations")]
public void TestCaptureAndForwardingTogether(string inputStr, string[] expectedWrites) 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; expectedWrites[i] += Environment.NewLine;
} }

View file

@ -1,13 +1,13 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // 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.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel;
namespace Microsoft.DotNet.Tools.Test.Utilities namespace Microsoft.DotNet.Tools.Test.Utilities
{ {
@ -69,10 +69,10 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
string config = string.IsNullOrEmpty(_config) ? "Debug" : _config; string config = string.IsNullOrEmpty(_config) ? "Debug" : _config;
string framework = string.IsNullOrEmpty(_framework) ? string framework = string.IsNullOrEmpty(_framework) ?
_project.GetTargetFrameworks().First().FrameworkName.GetShortFolderName() : _framework; _project.GetTargetFrameworks().First().FrameworkName.GetShortFolderName() : _framework;
if (!portable) 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); return Path.Combine(config, framework, runtime, PublishSubfolderName);
} }
else else
@ -120,7 +120,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}"; private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o \"{_output}\""; private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o \"{_output}\"";
private string ConfigOption => string.IsNullOrEmpty(_config) ? "" : $"-c {_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}"; private string BuildBasePathOption => string.IsNullOrEmpty(_buidBasePathDirectory) ? "" : $"-b {_buidBasePathDirectory}";
} }
} }

View file

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // 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; using Xunit;
namespace Microsoft.DotNet.Tools.Test.Utilities namespace Microsoft.DotNet.Tools.Test.Utilities
@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
{ {
public WindowsOnlyFactAttribute() public WindowsOnlyFactAttribute()
{ {
if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{ {
this.Skip = "This test requires windows to run"; this.Skip = "This test requires windows to run";
} }
@ -21,7 +21,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
{ {
public WindowsOnlyTheoryAttribute() public WindowsOnlyTheoryAttribute()
{ {
if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{ {
this.Skip = "This test requires windows to run"; this.Skip = "This test requires windows to run";
} }

View file

@ -5,11 +5,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using FluentAssertions; using FluentAssertions;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Extensions.DependencyModel.Resolution; using Microsoft.Extensions.DependencyModel.Resolution;
using Microsoft.Extensions.PlatformAbstractions;
using Moq;
using Xunit; using Xunit;
using F = Microsoft.Extensions.DependencyModel.Tests.TestLibraryFactory; using F = Microsoft.Extensions.DependencyModel.Tests.TestLibraryFactory;
namespace Microsoft.Extensions.DependencyModel.Tests namespace Microsoft.Extensions.DependencyModel.Tests
@ -21,13 +19,11 @@ namespace Microsoft.Extensions.DependencyModel.Tests
[Fact] [Fact]
public void SholdUseEnvironmentVariableToGetDefaultLocation() public void SholdUseEnvironmentVariableToGetDefaultLocation()
{ {
var runtime = new Mock<IRuntimeEnvironment>();
var environment = EnvironmentMockBuilder.Create() var environment = EnvironmentMockBuilder.Create()
.AddVariable("NUGET_PACKAGES", PackagesPath) .AddVariable("NUGET_PACKAGES", PackagesPath)
.Build(); .Build();
var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(runtime.Object, environment); var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(Platform.Unknown, environment);
result.Should().Be(PackagesPath); result.Should().Be(PackagesPath);
} }
@ -35,28 +31,22 @@ namespace Microsoft.Extensions.DependencyModel.Tests
[Fact] [Fact]
public void SholdUseNugetUnderUserProfileOnWindows() public void SholdUseNugetUnderUserProfileOnWindows()
{ {
var runtime = new Mock<IRuntimeEnvironment>();
runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Windows);
var environment = EnvironmentMockBuilder.Create() var environment = EnvironmentMockBuilder.Create()
.AddVariable("USERPROFILE", "User Profile") .AddVariable("USERPROFILE", "User Profile")
.Build(); .Build();
var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(runtime.Object, environment); var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(Platform.Windows, environment);
result.Should().Be(Path.Combine("User Profile", ".nuget", "packages")); result.Should().Be(Path.Combine("User Profile", ".nuget", "packages"));
} }
[Fact] [Fact]
public void SholdUseNugetUnderHomeOnNonWindows() public void SholdUseNugetUnderHomeOnNonWindows()
{ {
var runtime = new Mock<IRuntimeEnvironment>();
runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Linux);
var environment = EnvironmentMockBuilder.Create() var environment = EnvironmentMockBuilder.Create()
.AddVariable("HOME", "User Home") .AddVariable("HOME", "User Home")
.Build(); .Build();
var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(runtime.Object, environment); var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(Platform.Linux, environment);
result.Should().Be(Path.Combine("User Home", ".nuget", "packages")); result.Should().Be(Path.Combine("User Home", ".nuget", "packages"));
} }

View file

@ -5,11 +5,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using FluentAssertions; using FluentAssertions;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Extensions.DependencyModel.Resolution; using Microsoft.Extensions.DependencyModel.Resolution;
using Microsoft.Extensions.PlatformAbstractions;
using Moq;
using Xunit; using Xunit;
using F = Microsoft.Extensions.DependencyModel.Tests.TestLibraryFactory; using F = Microsoft.Extensions.DependencyModel.Tests.TestLibraryFactory;
@ -34,53 +32,41 @@ namespace Microsoft.Extensions.DependencyModel.Tests
[Fact] [Fact]
public void UsesEnvironmentVariableForDefaultPath() public void UsesEnvironmentVariableForDefaultPath()
{ {
var runtime = new Mock<IRuntimeEnvironment>();
runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Windows);
var environment = EnvironmentMockBuilder.Create() var environment = EnvironmentMockBuilder.Create()
.AddVariable("DOTNET_REFERENCE_ASSEMBLIES_PATH", ReferencePath) .AddVariable("DOTNET_REFERENCE_ASSEMBLIES_PATH", ReferencePath)
.Build(); .Build();
var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, FileSystemMockBuilder.Empty, environment); var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(FileSystemMockBuilder.Empty, Platform.Windows, environment);
result.Should().Be(ReferencePath); result.Should().Be(ReferencePath);
} }
[Fact] [Fact]
public void LooksOnlyOnEnvironmentVariableOnNonWindows() public void LooksOnlyOnEnvironmentVariableOnNonWindows()
{ {
var runtime = new Mock<IRuntimeEnvironment>(); var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(FileSystemMockBuilder.Empty, Platform.Linux, EnvironmentMockBuilder.Empty);
runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Linux);
var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, FileSystemMockBuilder.Empty, EnvironmentMockBuilder.Empty);
result.Should().BeNull(); result.Should().BeNull();
} }
[Fact] [Fact]
public void ReturnsProgramFiles86AsDefaultLocationOnWin64() public void ReturnsProgramFiles86AsDefaultLocationOnWin64()
{ {
var runtime = new Mock<IRuntimeEnvironment>();
runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Windows);
var environment = EnvironmentMockBuilder.Create() var environment = EnvironmentMockBuilder.Create()
.AddVariable("ProgramFiles(x86)", "Program Files (x86)") .AddVariable("ProgramFiles(x86)", "Program Files (x86)")
.AddVariable("ProgramFiles", "Program Files") .AddVariable("ProgramFiles", "Program Files")
.Build(); .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")); result.Should().Be(Path.Combine("Program Files (x86)", "Reference Assemblies", "Microsoft", "Framework"));
} }
[Fact] [Fact]
public void ReturnsProgramFilesAsDefaultLocationOnWin32() public void ReturnsProgramFilesAsDefaultLocationOnWin32()
{ {
var runtime = new Mock<IRuntimeEnvironment>();
runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Windows);
var environment = EnvironmentMockBuilder.Create() var environment = EnvironmentMockBuilder.Create()
.AddVariable("ProgramFiles", "Program Files") .AddVariable("ProgramFiles", "Program Files")
.Build(); .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")); result.Should().Be(Path.Combine("Program Files", "Reference Assemblies", "Microsoft", "Framework"));
} }
@ -92,14 +78,11 @@ namespace Microsoft.Extensions.DependencyModel.Tests
.AddFiles(net20Path, "some.dll") .AddFiles(net20Path, "some.dll")
.Build(); .Build();
var runtime = new Mock<IRuntimeEnvironment>();
runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Windows);
var environment = EnvironmentMockBuilder.Create() var environment = EnvironmentMockBuilder.Create()
.AddVariable("WINDIR", "Windows") .AddVariable("WINDIR", "Windows")
.Build(); .Build();
var result = ReferenceAssemblyPathResolver.GetFallbackSearchPaths(fileSystem, runtime.Object, environment); var result = ReferenceAssemblyPathResolver.GetFallbackSearchPaths(fileSystem, Platform.Windows, environment);
result.Should().Contain(net20Path); result.Should().Contain(net20Path);
} }

View file

@ -3,13 +3,8 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Xunit.Performance; using Microsoft.Xunit.Performance;
using Xunit;
using System.Diagnostics;
namespace Microsoft.DotNet.Tests.Performance namespace Microsoft.DotNet.Tests.Performance
{ {

View file

@ -6,14 +6,10 @@ using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Xml.Linq; 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 FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tests namespace Microsoft.DotNet.Tests
{ {

View file

@ -1,16 +1,10 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // 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.IO;
using System.Linq; using Microsoft.DotNet.InternalAbstractions;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.TestFramework;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tests namespace Microsoft.DotNet.Tests
{ {
@ -21,7 +15,7 @@ namespace Microsoft.DotNet.Tests
private const string AppWithConfig = "AppWithRedirectsAndConfig"; private const string AppWithConfig = "AppWithRedirectsAndConfig";
private const string AppWithoutConfig = "AppWithRedirectsNoConfig"; 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 _desktopProjectsRoot = Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects");
private string _buildRelativePath; private string _buildRelativePath;
private string _appWithConfigProjectRoot; private string _appWithConfigProjectRoot;

View file

@ -6,9 +6,9 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using FluentAssertions; using FluentAssertions;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NuGet.Frameworks; using NuGet.Frameworks;
using Xunit; using Xunit;
@ -69,7 +69,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
var contexts = ProjectContext.CreateContextForEachFramework( var contexts = ProjectContext.CreateContextForEachFramework(
_testAppDirDirInfo.FullName, _testAppDirDirInfo.FullName,
null, null,
PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
_runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier; _runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier;
} }
@ -177,9 +177,9 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
} }
[Theory] [Theory]
// [InlineData("net20", false, true)] // [InlineData("net20", false, true)]
// [InlineData("net40", true, true)] // [InlineData("net40", true, true)]
// [InlineData("net461", true, true)] // [InlineData("net461", true, true)]
[InlineData("netstandard1.5", true, false)] [InlineData("netstandard1.5", true, false)]
public void MultipleFrameworks_ShouldHaveValidTargetFrameworkAttribute(string frameworkName, bool shouldHaveTargetFrameworkAttribute, bool windowsOnly) public void MultipleFrameworks_ShouldHaveValidTargetFrameworkAttribute(string frameworkName, bool shouldHaveTargetFrameworkAttribute, bool windowsOnly)
{ {

View file

@ -2,14 +2,14 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO; using System.IO;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.DotNet.ProjectModel;
using Microsoft.Extensions.PlatformAbstractions;
using Xunit;
using System.Linq; using System.Linq;
using Microsoft.DotNet.TestFramework;
using Newtonsoft.Json.Linq;
using FluentAssertions; 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 namespace Microsoft.DotNet.Tools.Builder.Tests
{ {
@ -72,7 +72,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
var contexts = ProjectContext.CreateContextForEachFramework( var contexts = ProjectContext.CreateContextForEachFramework(
projectPath, projectPath,
null, null,
PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
var runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier; var runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier;

View file

@ -4,14 +4,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Moq; using Moq;
using NuGet.Frameworks; using NuGet.Frameworks;
using Xunit; using Xunit;
using Microsoft.DotNet.Cli.Utils;
using FluentAssertions;
using System.Linq;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Tools.Compiler.Tests namespace Microsoft.DotNet.Tools.Compiler.Tests
{ {
@ -70,7 +69,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
[Fact] [Fact]
public void It_passes_a_RuntimeOutputDir_variable_to_the_pre_compile_scripts_if_rid_is_set_in_the_ProjectContext() 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); var fixture = ScriptVariablesFixture.GetFixtureWithRids(rid);
fixture.PreCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir"); fixture.PreCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir");
fixture.PreCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir); fixture.PreCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir);
@ -129,7 +128,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
[Fact] [Fact]
public void It_passes_a_RuntimeOutputDir_variable_to_the_post_compile_scripts_if_rid_is_set_in_the_ProjectContext() 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); var fixture = ScriptVariablesFixture.GetFixtureWithRids(rid);
fixture.PostCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir"); fixture.PostCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir");
fixture.PostCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir); fixture.PostCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir);

View file

@ -1,14 +1,11 @@
using System.Diagnostics; using System.IO;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using FluentAssertions; using FluentAssertions;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Xunit; using Xunit;
namespace Microsoft.DotNet.Tools.Publish.Tests namespace Microsoft.DotNet.Tools.Publish.Tests
@ -28,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[InlineData("win7-x86", "the-win-x86-version.txt")] [InlineData("win7-x86", "the-win-x86-version.txt")]
public async Task DesktopApp_WithDependencyOnNativePackage_ProducesExpectedOutput(string runtime, string expectedOutputName) 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"; 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)] [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) 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() var testInstance = GetTestInstance()
.WithLockFiles(); .WithLockFiles();

Some files were not shown because too many files have changed in this diff Show more