2016-03-10 16:01:11 -08:00
|
|
|
// 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.
|
|
|
|
|
2016-04-28 16:30:32 -07:00
|
|
|
using Microsoft.DotNet.InternalAbstractions;
|
2016-03-10 16:01:11 -08:00
|
|
|
using Microsoft.Extensions.EnvironmentAbstractions;
|
|
|
|
|
|
|
|
namespace Microsoft.Extensions.DependencyModel.Resolution
|
|
|
|
{
|
|
|
|
public class DotNetReferenceAssembliesPathResolver
|
|
|
|
{
|
|
|
|
public static readonly string DotNetReferenceAssembliesPathEnv = "DOTNET_REFERENCE_ASSEMBLIES_PATH";
|
2016-04-22 15:01:56 -07:00
|
|
|
|
2016-04-28 16:30:32 -07:00
|
|
|
internal static string Resolve(IEnvironment envirnment, IFileSystem fileSystem)
|
2016-03-10 16:01:11 -08:00
|
|
|
{
|
|
|
|
var path = envirnment.GetEnvironmentVariable(DotNetReferenceAssembliesPathEnv);
|
|
|
|
if (!string.IsNullOrEmpty(path))
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
2016-04-22 15:01:56 -07:00
|
|
|
|
2016-04-28 16:30:32 -07:00
|
|
|
return GetDefaultDotNetReferenceAssembliesPath(fileSystem);
|
2016-03-10 16:01:11 -08:00
|
|
|
}
|
2016-04-22 15:01:56 -07:00
|
|
|
|
2016-03-10 16:01:11 -08:00
|
|
|
public static string Resolve()
|
|
|
|
{
|
2016-04-28 16:30:32 -07:00
|
|
|
return Resolve(EnvironmentWrapper.Default, FileSystemWrapper.Default);
|
2016-03-10 16:01:11 -08:00
|
|
|
}
|
2016-04-22 15:01:56 -07:00
|
|
|
|
2016-04-28 16:30:32 -07:00
|
|
|
private static string GetDefaultDotNetReferenceAssembliesPath(IFileSystem fileSystem)
|
2016-04-22 15:01:56 -07:00
|
|
|
{
|
2016-04-28 16:30:32 -07:00
|
|
|
var os = RuntimeEnvironment.OperatingSystemPlatform;
|
2016-04-22 15:01:56 -07:00
|
|
|
|
2016-03-10 16:01:11 -08:00
|
|
|
if (os == Platform.Windows)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2016-04-22 15:01:56 -07:00
|
|
|
|
|
|
|
if (os == Platform.Darwin &&
|
2016-03-11 11:51:31 -08:00
|
|
|
fileSystem.Directory.Exists("/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks"))
|
2016-03-10 16:01:11 -08:00
|
|
|
{
|
2016-03-11 11:51:31 -08:00
|
|
|
return "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks";
|
2016-03-10 16:01:11 -08:00
|
|
|
}
|
2016-04-22 15:01:56 -07:00
|
|
|
|
2016-03-10 16:43:58 -08:00
|
|
|
if (fileSystem.Directory.Exists("/usr/local/lib/mono/xbuild-frameworks"))
|
2016-03-10 16:01:11 -08:00
|
|
|
{
|
|
|
|
return "/usr/local/lib/mono/xbuild-frameworks";
|
|
|
|
}
|
2016-04-22 15:01:56 -07:00
|
|
|
|
2016-03-10 16:43:58 -08:00
|
|
|
if (fileSystem.Directory.Exists("/usr/lib/mono/xbuild-frameworks"))
|
2016-03-10 16:01:11 -08:00
|
|
|
{
|
|
|
|
return "/usr/lib/mono/xbuild-frameworks";
|
|
|
|
}
|
2016-04-22 15:01:56 -07:00
|
|
|
|
2016-03-10 16:01:11 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2016-03-11 11:51:31 -08:00
|
|
|
}
|