Merge branch 'troy/531' into rel/1.0.0

This commit is contained in:
Troy Dai 2016-03-11 09:53:18 -08:00
commit 429625061d
4 changed files with 72 additions and 12 deletions

View file

@ -8,6 +8,7 @@ using System.Linq;
using System.Runtime.Versioning;
using System.Xml.Linq;
using Microsoft.DotNet.ProjectModel.Utilities;
using Microsoft.Extensions.DependencyModel.Resolution;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
@ -53,7 +54,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
public static string GetDefaultReferenceAssembliesPath()
{
// Allow setting the reference assemblies path via an environment variable
var referenceAssembliesPath = Environment.GetEnvironmentVariable("DOTNET_REFERENCE_ASSEMBLIES_PATH");
var referenceAssembliesPath = DotNetReferenceAssembliesPathResolver.Resolve();
if (!string.IsNullOrEmpty(referenceAssembliesPath))
{
@ -207,7 +208,9 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
private static FrameworkInformation GetFrameworkInformation(NuGetFramework targetFramework, string referenceAssembliesPath)
{
// Check for legacy frameworks
if (targetFramework.IsDesktop() && targetFramework.Version <= new Version(3, 5))
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows &&
targetFramework.IsDesktop() &&
targetFramework.Version <= new Version(3, 5))
{
return GetLegacyFrameworkInformation(targetFramework, referenceAssembliesPath);
}

View file

@ -0,0 +1,59 @@
// 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.Extensions.EnvironmentAbstractions;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.Extensions.DependencyModel.Resolution
{
public class DotNetReferenceAssembliesPathResolver
{
public static readonly string DotNetReferenceAssembliesPathEnv = "DOTNET_REFERENCE_ASSEMBLIES_PATH";
internal static string Resolve(IEnvironment envirnment, IFileSystem fileSystem, IRuntimeEnvironment runtimeEnvironment)
{
var path = envirnment.GetEnvironmentVariable(DotNetReferenceAssembliesPathEnv);
if (!string.IsNullOrEmpty(path))
{
return path;
}
return GetDefaultDotNetReferenceAssembliesPath(fileSystem, runtimeEnvironment);
}
public static string Resolve()
{
return Resolve(EnvironmentWrapper.Default, FileSystemWrapper.Default, PlatformServices.Default.Runtime);
}
private static string GetDefaultDotNetReferenceAssembliesPath(IFileSystem fileSystem, IRuntimeEnvironment runtimeEnvironment)
{
var os = runtimeEnvironment.OperatingSystemPlatform;
if (os == Platform.Windows)
{
return null;
}
if (os == Platform.Darwin &&
fileSystem.Directory.Exists("/Library/Framework/Mono.Framework/Versions/Current/lib/mono/xbuild-frameworks"))
{
return "/Library/Framework/Mono.Framework/Versions/Current/lib/mono/xbuild-frameworks";
}
if (fileSystem.Directory.Exists("/usr/local/lib/mono/xbuild-frameworks"))
{
return "/usr/local/lib/mono/xbuild-frameworks";
}
if (fileSystem.Directory.Exists("/usr/lib/mono/xbuild-frameworks"))
{
return "/usr/lib/mono/xbuild-frameworks";
}
return null;
}
}
}

View file

@ -27,7 +27,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
internal ReferenceAssemblyPathResolver(IFileSystem fileSystem, IRuntimeEnvironment runtimeEnvironment, IEnvironment environment)
: this(fileSystem,
GetDefaultReferenceAssembliesPath(runtimeEnvironment, environment),
GetDefaultReferenceAssembliesPath(runtimeEnvironment, fileSystem, environment),
GetFallbackSearchPaths(fileSystem, runtimeEnvironment, environment))
{
}
@ -101,11 +101,10 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
return new[] { net20Dir };
}
internal static string GetDefaultReferenceAssembliesPath(IRuntimeEnvironment runtimeEnvironment, IEnvironment environment)
internal static string GetDefaultReferenceAssembliesPath(IRuntimeEnvironment runtimeEnvironment, IFileSystem fileSystem, IEnvironment environment)
{
// Allow setting the reference assemblies path via an environment variable
var referenceAssembliesPath = environment.GetEnvironmentVariable("DOTNET_REFERENCE_ASSEMBLIES_PATH");
var referenceAssembliesPath = DotNetReferenceAssembliesPathResolver.Resolve(environment, fileSystem, runtimeEnvironment);
if (!string.IsNullOrEmpty(referenceAssembliesPath))
{
return referenceAssembliesPath;
@ -138,6 +137,5 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
programFiles,
"Reference Assemblies", "Microsoft", "Framework");
}
}
}

View file

@ -36,12 +36,12 @@ namespace Microsoft.Extensions.DependencyModel.Tests
{
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, environment);
var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, FileSystemMockBuilder.Empty, environment);
result.Should().Be(ReferencePath);
}
@ -51,7 +51,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
var runtime = new Mock<IRuntimeEnvironment>();
runtime.SetupGet(r => r.OperatingSystemPlatform).Returns(Platform.Linux);
var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, EnvironmentMockBuilder.Empty);
var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, FileSystemMockBuilder.Empty, EnvironmentMockBuilder.Empty);
result.Should().BeNull();
}
@ -66,7 +66,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
.AddVariable("ProgramFiles", "Program Files")
.Build();
var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, environment);
var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, FileSystemMockBuilder.Empty, environment);
result.Should().Be(Path.Combine("Program Files (x86)", "Reference Assemblies", "Microsoft", "Framework"));
}
@ -80,7 +80,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
.AddVariable("ProgramFiles", "Program Files")
.Build();
var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, environment);
var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(runtime.Object, FileSystemMockBuilder.Empty, environment);
result.Should().Be(Path.Combine("Program Files", "Reference Assemblies", "Microsoft", "Framework"));
}