Merge pull request #2747 from dotnet/prkrishn/remove-platformabstractions

Replaces references to Microsoft.Extensions.PlatformAbstractions
This commit is contained in:
Pranav K 2016-04-29 17:54:22 -07:00
commit f8631fa4b7
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
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Performance", "test\Performance\Performance.xproj", "{6A3095FF-A7C5-4300-85A9-C025C384401D}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "binding-redirects.Tests", "test\binding-redirects.Tests\binding-redirects.Tests.xproj", "{27DBF851-F2E3-4FD5-BF4D-A73C81933283}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -777,6 +779,22 @@ Global
{6A3095FF-A7C5-4300-85A9-C025C384401D}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{6A3095FF-A7C5-4300-85A9-C025C384401D}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{6A3095FF-A7C5-4300-85A9-C025C384401D}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Debug|x64.ActiveCfg = Debug|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Debug|x64.Build.0 = Debug|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Release|Any CPU.Build.0 = Release|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Release|x64.ActiveCfg = Release|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.Release|x64.Build.0 = Release|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{27DBF851-F2E3-4FD5-BF4D-A73C81933283}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -828,5 +846,6 @@ Global
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{6A3095FF-A7C5-4300-85A9-C025C384401D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{27DBF851-F2E3-4FD5-BF4D-A73C81933283} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
EndGlobalSection
EndGlobal

View file

@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Filter;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.PlatformAbstractions;
namespace SampleApp
{
@ -21,7 +20,7 @@ namespace SampleApp
private static string Args { get; set; }
private static CancellationTokenSource ServerCancellationTokenSource { get; set; }
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env)
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
var ksi = app.ServerFeatures.Get<IKestrelServerInformation>();
ksi.NoDelay = true;

View file

@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Filter;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.PlatformAbstractions;
namespace SampleApp
{
@ -21,7 +20,7 @@ namespace SampleApp
private static string Args { get; set; }
private static CancellationTokenSource ServerCancellationTokenSource { get; set; }
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env)
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
var ksi = app.ServerFeatures.Get<IKestrelServerInformation>();
ksi.NoDelay = true;

View file

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

View file

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

View file

@ -1,10 +1,19 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"warningsAsErrors": true,
"allowUnsafe": true
},
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027",
"System.Diagnostics.Process": "4.1.0-rc2-24027",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-20581"
"System.Reflection.TypeExtensions": "4.1.0-rc2-24027"
},
"compile": [
"../../src/Microsoft.DotNet.InternalAbstractions/RuntimeEnvironment.cs",
"../../src/Microsoft.DotNet.InternalAbstractions/Platform.cs",
"../../src/Microsoft.DotNet.InternalAbstractions/Native/*.cs"
],
"frameworks": {
"netstandard1.3": {
"imports": "dnxcore50"

View file

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

View file

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

View file

@ -1,12 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using Microsoft.DotNet.Cli.Build.Framework;
namespace Microsoft.DotNet.Cli.Build
{

View file

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

View file

@ -4,8 +4,7 @@ using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
@ -261,11 +260,11 @@ namespace Microsoft.DotNet.Cli.Build
// This is overkill, but I want to cover all the variables used in all OSes (including where some have the same names)
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
var configuration = c.BuildContext.Get<string>("Configuration");
var architecture = PlatformServices.Default.Runtime.RuntimeArchitecture;
var architecture = RuntimeEnvironment.RuntimeArchitecture;
var env = new Dictionary<string, string>()
{
{ "RID", PlatformServices.Default.Runtime.GetRuntimeIdentifier() },
{ "OSNAME", PlatformServices.Default.Runtime.OperatingSystem },
{ "RID", RuntimeEnvironment.GetRuntimeIdentifier() },
{ "OSNAME", RuntimeEnvironment.OperatingSystem },
{ "TFM", "dnxcore50" },
{ "REPOROOT", Dirs.RepoRoot },
{ "OutputDir", Dirs.Output },

View file

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

View file

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

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 static Microsoft.DotNet.Cli.Build.FS;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using static Microsoft.DotNet.Cli.Build.Utils;
namespace Microsoft.DotNet.Cli.Build
{
public static class TestPackageProjects

View file

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

View file

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

View file

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

View file

@ -1,13 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils
{
public abstract class AbstractPathBasedCommandResolver : ICommandResolver

View file

@ -1,24 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
public class AppBaseCommandResolver : AbstractPathBasedCommandResolver
{
public AppBaseCommandResolver(IEnvironmentProvider environment,
public AppBaseCommandResolver(IEnvironmentProvider environment,
IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { }
internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments)
{
return _environment.GetCommandPathFromRootPath(
PlatformServices.Default.Application.ApplicationBasePath,
ApplicationEnvironment.ApplicationBasePath,
commandResolverArguments.CommandName);
}

View file

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

View file

@ -1,13 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils
{
@ -15,9 +6,9 @@ namespace Microsoft.DotNet.Cli.Utils
{
private IList<ICommandResolver> _orderedCommandResolvers;
public IEnumerable<ICommandResolver> OrderedCommandResolvers
public IEnumerable<ICommandResolver> OrderedCommandResolvers
{
get
get
{
return _orderedCommandResolvers;
}
@ -32,7 +23,7 @@ namespace Microsoft.DotNet.Cli.Utils
{
_orderedCommandResolvers.Add(commandResolver);
}
public CommandSpec Resolve(CommandResolverArguments commandResolverArguments)
{
foreach (var commandResolver in _orderedCommandResolvers)

View file

@ -1,13 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
@ -19,7 +10,7 @@ namespace Microsoft.DotNet.Cli.Utils
var packagedCommandSpecFactory = new PackagedCommandSpecFactory();
var platformCommandSpecFactory = default(IPlatformCommandSpecFactory);
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
}

View file

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

View file

@ -1,13 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils
{

View file

@ -1,13 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils
{

View file

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

View file

@ -1,19 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils
namespace Microsoft.DotNet.Cli.Utils
{
public class PathCommandResolver : AbstractPathBasedCommandResolver
{
public PathCommandResolver(IEnvironmentProvider environment,
public PathCommandResolver(IEnvironmentProvider environment,
IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { }
internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments)

View file

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

View file

@ -1,19 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils
namespace Microsoft.DotNet.Cli.Utils
{
public class ProjectPathCommandResolver : AbstractPathBasedCommandResolver
{
public ProjectPathCommandResolver(IEnvironmentProvider environment,
public ProjectPathCommandResolver(IEnvironmentProvider environment,
IPlatformCommandSpecFactory commandSpecFactory) : base(environment, commandSpecFactory) { }
internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments)
@ -24,7 +13,7 @@ namespace Microsoft.DotNet.Cli.Utils
}
return _environment.GetCommandPathFromRootPath(
commandResolverArguments.ProjectDirectory,
commandResolverArguments.ProjectDirectory,
commandResolverArguments.CommandName,
commandResolverArguments.InferredExtensions.OrEmptyIfNull());
}

View file

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

View file

@ -1,13 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
using System.IO;
namespace Microsoft.DotNet.Cli.Utils
{

View file

@ -1,13 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
@ -18,7 +9,7 @@ namespace Microsoft.DotNet.Cli.Utils
var environment = new EnvironmentProvider();
var platformCommandSpecFactory = default(IPlatformCommandSpecFactory);
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
}

View file

@ -2,12 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils
{
@ -36,7 +30,7 @@ namespace Microsoft.DotNet.Cli.Utils
}
}
return useCmdWrapper
return useCmdWrapper
? CreateCommandSpecWrappedWithCmd(commandPath, args, resolutionStrategy)
: CreateCommandSpecFromExecutable(commandPath, args, resolutionStrategy);
}

View file

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

View file

@ -1,13 +1,13 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
public static class Constants
{
private static Platform CurrentPlatform => PlatformServices.Default.Runtime.OperatingSystemPlatform;
private static Platform CurrentPlatform => RuntimeEnvironment.OperatingSystemPlatform;
public const string DefaultConfiguration = "Debug";
public static readonly string ProjectFileName = "project.json";

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,9 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
// Stupid-simple console manager

View file

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

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": {
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
},
"dependencies": {
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-20581"
"keyFile": "../../tools/Key.snk",
"allowUnsafe": true
},
"frameworks": {
"net451": {},
"netstandard1.3": {}
"net451": { },
"netstandard1.3": {
"dependencies": {
"System.AppContext": "4.1.0-rc2-24027",
"System.Collections": "4.0.11-rc2-24027",
"System.IO": "4.1.0-rc2-24027",
"System.IO.FileSystem": "4.0.1-rc2-24027",
"System.Reflection.TypeExtensions": "4.1.0-rc2-24027",
"System.Runtime.Extensions": "4.1.0-rc2-24027",
"System.Runtime.InteropServices": "4.1.0-rc2-24027",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-rc2-24027"
}
}
},
"scripts": {}
"scripts": { }
}

View file

@ -12,9 +12,9 @@ using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text;
using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.DotNet.ProjectModel.Files;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
namespace Microsoft.DotNet.ProjectModel.Workspaces
@ -225,7 +225,7 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces
{
keyFile = Path.GetFullPath(Path.Combine(projectDirectory, compilerOptions.KeyFile));
if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Extensions.PlatformAbstractions.Platform.Windows || useOssSigning)
if (RuntimeEnvironment.OperatingSystemPlatform != InternalAbstractions.Platform.Windows || useOssSigning)
{
return options.WithCryptoPublicKey(
SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile)));

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace Microsoft.Extensions.PlatformAbstractions
namespace Microsoft.DotNet.InternalAbstractions
{
// This is to support some legacy stuff.
// dnu restore (and thus dotnet restore) always uses win7-x64 as the Windows restore target,
@ -12,11 +12,11 @@ namespace Microsoft.Extensions.PlatformAbstractions
public static class RuntimeEnvironmentRidExtensions
{
// Work around NuGet/Home#1941
public static IEnumerable<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
{
@ -26,44 +26,44 @@ namespace Microsoft.Extensions.PlatformAbstractions
}
// Gets the identfier that is used for restore by default (this is different from the actual RID, but only on Windows)
public static string GetLegacyRestoreRuntimeIdentifier(this IRuntimeEnvironment env)
public static string GetLegacyRestoreRuntimeIdentifier()
{
if (env.OperatingSystemPlatform != Platform.Windows)
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{
return env.GetRuntimeIdentifier();
return RuntimeEnvironment.GetRuntimeIdentifier();
}
else
{
var arch = env.RuntimeArchitecture.ToLowerInvariant();
var arch = RuntimeEnvironment.RuntimeArchitecture.ToLowerInvariant();
return "win7-" + arch;
}
}
public static IEnumerable<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
{
var arch = env.RuntimeArchitecture.ToLowerInvariant();
if (env.OperatingSystemVersion.StartsWith("6.1", StringComparison.Ordinal))
var arch = RuntimeEnvironment.RuntimeArchitecture.ToLowerInvariant();
if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("6.1", StringComparison.Ordinal))
{
yield return "win7-" + arch;
}
else if (env.OperatingSystemVersion.StartsWith("6.2", StringComparison.Ordinal))
else if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("6.2", StringComparison.Ordinal))
{
yield return "win8-" + arch;
yield return "win7-" + arch;
}
else if (env.OperatingSystemVersion.StartsWith("6.3", StringComparison.Ordinal))
else if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("6.3", StringComparison.Ordinal))
{
yield return "win81-" + arch;
yield return "win8-" + arch;
yield return "win7-" + arch;
}
else if (env.OperatingSystemVersion.StartsWith("10.0", StringComparison.Ordinal))
else if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("10.0", StringComparison.Ordinal))
{
yield return "win10-" + arch;
yield return "win81-" + arch;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.Extensions.DependencyModel.Resolution
@ -15,7 +15,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
private readonly string _nugetPackageDirectory;
public PackageCompilationAssemblyResolver()
: this(EnvironmentWrapper.Default, PlatformServices.Default.Runtime, FileSystemWrapper.Default)
: this(EnvironmentWrapper.Default, FileSystemWrapper.Default)
{
}
@ -25,9 +25,8 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
}
internal PackageCompilationAssemblyResolver(IEnvironment environment,
IRuntimeEnvironment runtimeEnvironment,
IFileSystem fileSystem)
: this(fileSystem, GetDefaultPackageDirectory(runtimeEnvironment, environment))
: this(fileSystem, GetDefaultPackageDirectory(environment))
{
}
@ -37,7 +36,10 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
_nugetPackageDirectory = nugetPackageDirectory;
}
internal static string GetDefaultPackageDirectory(IRuntimeEnvironment runtimeEnvironment, IEnvironment environment)
private static string GetDefaultPackageDirectory(IEnvironment environment) =>
GetDefaultPackageDirectory(RuntimeEnvironment.OperatingSystemPlatform, environment);
internal static string GetDefaultPackageDirectory(Platform osPlatform, IEnvironment environment)
{
var packageDirectory = environment.GetEnvironmentVariable("NUGET_PACKAGES");
@ -47,7 +49,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
}
string basePath;
if (runtimeEnvironment.OperatingSystemPlatform == Platform.Windows)
if (osPlatform == Platform.Windows)
{
basePath = environment.GetEnvironmentVariable("USERPROFILE");
}

View file

@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.Extensions.DependencyModel.Resolution
@ -16,7 +16,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
private readonly string[] _fallbackSearchPaths;
public ReferenceAssemblyPathResolver()
: this(FileSystemWrapper.Default, PlatformServices.Default.Runtime, EnvironmentWrapper.Default)
: this(FileSystemWrapper.Default, EnvironmentWrapper.Default)
{
}
@ -25,10 +25,10 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
{
}
internal ReferenceAssemblyPathResolver(IFileSystem fileSystem, IRuntimeEnvironment runtimeEnvironment, IEnvironment environment)
internal ReferenceAssemblyPathResolver(IFileSystem fileSystem, IEnvironment environment)
: this(fileSystem,
GetDefaultReferenceAssembliesPath(runtimeEnvironment, fileSystem, environment),
GetFallbackSearchPaths(fileSystem, runtimeEnvironment, environment))
GetDefaultReferenceAssembliesPath(fileSystem, RuntimeEnvironment.OperatingSystemPlatform, environment),
GetFallbackSearchPaths(fileSystem, RuntimeEnvironment.OperatingSystemPlatform, environment))
{
}
@ -85,9 +85,9 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
return false;
}
internal static string[] GetFallbackSearchPaths(IFileSystem fileSystem, IRuntimeEnvironment runtimeEnvironment, IEnvironment environment)
internal static string[] GetFallbackSearchPaths(IFileSystem fileSystem, Platform platform, IEnvironment environment)
{
if (runtimeEnvironment.OperatingSystemPlatform != Platform.Windows)
if (platform != Platform.Windows)
{
return new string[0];
}
@ -101,16 +101,16 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
return new[] { net20Dir };
}
internal static string GetDefaultReferenceAssembliesPath(IRuntimeEnvironment runtimeEnvironment, IFileSystem fileSystem, IEnvironment environment)
internal static string GetDefaultReferenceAssembliesPath(IFileSystem fileSystem, Platform platform, IEnvironment environment)
{
// Allow setting the reference assemblies path via an environment variable
var referenceAssembliesPath = DotNetReferenceAssembliesPathResolver.Resolve(environment, fileSystem, runtimeEnvironment);
var referenceAssembliesPath = DotNetReferenceAssembliesPathResolver.Resolve(environment, fileSystem);
if (!string.IsNullOrEmpty(referenceAssembliesPath))
{
return referenceAssembliesPath;
}
if (runtimeEnvironment.OperatingSystemPlatform != Platform.Windows)
if (platform != Platform.Windows)
{
// There is no reference assemblies path outside of windows
// The environment variable can be used to specify one

View file

@ -26,7 +26,8 @@
"imports": "portable-net45+wp80+win8+wpa81+dnxcore50",
"dependencies": {
"System.Diagnostics.Debug": "4.0.11-rc2-24027",
"System.Dynamic.Runtime": "4.0.11-rc2-24027"
"System.Dynamic.Runtime": "4.0.11-rc2-24027",
"System.Linq": "4.1.0-rc2-24027"
}
}
},

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,21 +1,11 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;
using Xunit;
using Moq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using System.Threading;
using FluentAssertions;
using NuGet.Frameworks;
using Microsoft.DotNet.Tools.Test.Utilities;
using Moq;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests
{

View file

@ -1,21 +1,10 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;
using Xunit;
using Moq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using System.Threading;
using FluentAssertions;
using NuGet.Frameworks;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests
{

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.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;
using Xunit;
using Moq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.DotNet.TestFramework;
using System.Threading;
using FluentAssertions;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests
{

View file

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

View file

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

View file

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

View file

@ -1,21 +1,9 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;
using Xunit;
using Moq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using System.Threading;
using FluentAssertions;
using NuGet.Frameworks;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests
{
@ -78,7 +66,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "/some/rooted/path",
CommandArguments = new [] { "arg with space"}
CommandArguments = new[] { "arg with space" }
};
var result = rootedCommandResolver.Resolve(commandResolverArguments);

View file

@ -1,21 +1,10 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Xunit;
using Moq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using System.Threading;
using FluentAssertions;
using NuGet.Frameworks;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests
{
@ -33,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
resolvers.Select(r => r.GetType())
.Should()
.ContainInOrder(
new []{
new[]{
typeof(RootedCommandResolver),
typeof(MuxerCommandResolver),
typeof(ProjectPathCommandResolver),

View file

@ -2,20 +2,11 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;
using Xunit;
using Moq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using System.Threading;
using FluentAssertions;
using NuGet.Frameworks;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests
{
@ -107,7 +98,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "appbasetestcommand1",
CommandArguments = new [] { "arg with space"}
CommandArguments = new[] { "arg with space" }
};
var result = appBaseCommandResolver.Resolve(commandResolverArguments);
@ -163,12 +154,12 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
public void It_wraps_command_with_CMD_EXE_when_command_has_CMD_Extension_and_using_WindowsExePreferredCommandSpecFactory()
{
var environment = new EnvironmentProvider(new [] {".cmd"});
var environment = new EnvironmentProvider(new[] { ".cmd" });
var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory);
var testCommandPath =
var testCommandPath =
CommandResolverTestUtils.CreateNonRunnableTestCommand(AppContext.BaseDirectory, "cmdWrapCommand", ".cmd");
var commandResolverArguments = new CommandResolverArguments()
@ -193,9 +184,9 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
environment = environment ?? new EnvironmentProvider();
IPlatformCommandSpecFactory platformCommandSpecFactory = new GenericPlatformCommandSpecFactory();
IPlatformCommandSpecFactory platformCommandSpecFactory = new GenericPlatformCommandSpecFactory();
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows
&& !forceGeneric)
{
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();

View file

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

View file

@ -1,13 +1,13 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.Extensions.PlatformAbstractions;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
@ -69,10 +69,10 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
string config = string.IsNullOrEmpty(_config) ? "Debug" : _config;
string framework = string.IsNullOrEmpty(_framework) ?
_project.GetTargetFrameworks().First().FrameworkName.GetShortFolderName() : _framework;
if (!portable)
{
var runtime = string.IsNullOrEmpty(_runtime) ? PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier() : _runtime;
var runtime = string.IsNullOrEmpty(_runtime) ? RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier() : _runtime;
return Path.Combine(config, framework, runtime, PublishSubfolderName);
}
else
@ -120,7 +120,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o \"{_output}\"";
private string ConfigOption => string.IsNullOrEmpty(_config) ? "" : $"-c {_output}";
private string NoBuildFlag => _noBuild ? "--no-build" :"";
private string NoBuildFlag => _noBuild ? "--no-build" : "";
private string BuildBasePathOption => string.IsNullOrEmpty(_buidBasePathDirectory) ? "" : $"-b {_buidBasePathDirectory}";
}
}

View file

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.DotNet.InternalAbstractions;
using Xunit;
namespace Microsoft.DotNet.Tools.Test.Utilities
@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
{
public WindowsOnlyFactAttribute()
{
if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Platform.Windows)
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{
this.Skip = "This test requires windows to run";
}
@ -21,7 +21,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
{
public WindowsOnlyTheoryAttribute()
{
if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Platform.Windows)
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{
this.Skip = "This test requires windows to run";
}

View file

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

View file

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

View file

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

View file

@ -6,14 +6,10 @@ using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Xml.Linq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.DotNet.TestFramework;
using Microsoft.Extensions.PlatformAbstractions;
using Xunit;
using FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tests
{

View file

@ -1,16 +1,10 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.TestFramework;
using Microsoft.Extensions.PlatformAbstractions;
using Xunit;
using Microsoft.DotNet.Tools.Test.Utilities;
namespace Microsoft.DotNet.Tests
{
@ -21,7 +15,7 @@ namespace Microsoft.DotNet.Tests
private const string AppWithConfig = "AppWithRedirectsAndConfig";
private const string AppWithoutConfig = "AppWithRedirectsNoConfig";
private string _Runtime = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
private string _Runtime = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier();
private string _desktopProjectsRoot = Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects");
private string _buildRelativePath;
private string _appWithConfigProjectRoot;

View file

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

View file

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

View file

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

View file

@ -1,14 +1,11 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Xunit;
namespace Microsoft.DotNet.Tools.Publish.Tests
@ -28,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[InlineData("win7-x86", "the-win-x86-version.txt")]
public async Task DesktopApp_WithDependencyOnNativePackage_ProducesExpectedOutput(string runtime, string expectedOutputName)
{
if(string.IsNullOrEmpty(expectedOutputName))
if (string.IsNullOrEmpty(expectedOutputName))
{
expectedOutputName = $"the-win-{RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant()}-version.txt";
}
@ -57,7 +54,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[InlineData("KestrelDesktop", "http://localhost:20207", "win7-x86", "libuv.dll", false)]
public async Task DesktopApp_WithKestrel_WorksWhenPublished(string project, string url, string runtime, string libuvName, bool forceRunnable)
{
var runnable = forceRunnable || string.IsNullOrEmpty(runtime) || (PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier().Contains(runtime));
var runnable = forceRunnable || string.IsNullOrEmpty(runtime) || (RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier().Contains(runtime));
var testInstance = GetTestInstance()
.WithLockFiles();

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