diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/FrameworkReferenceResolver.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/FrameworkReferenceResolver.cs index 17458d0eb..e279a695e 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/FrameworkReferenceResolver.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/FrameworkReferenceResolver.cs @@ -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)) { diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/DotNetReferenceAssembliesPathResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/DotNetReferenceAssembliesPathResolver.cs new file mode 100644 index 000000000..5703b8d27 --- /dev/null +++ b/src/Microsoft.Extensions.DependencyModel/Resolution/DotNetReferenceAssembliesPathResolver.cs @@ -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) + { + var path = envirnment.GetEnvironmentVariable(DotNetReferenceAssembliesPathEnv); + if (!string.IsNullOrEmpty(path)) + { + return path; + } + + return GetDefaultDotNetReferenceAssembliesPath(); + } + + public static string Resolve() + { + return Resolve(EnvironmentWrapper.Default); + } + + private static string GetDefaultDotNetReferenceAssembliesPath() + { + var os = PlatformServices.Default.Runtime.OperatingSystemPlatform; + + if (os == Platform.Windows) + { + return null; + } + + if (os == Platform.Darwin && + Directory.Exists("/Library/Framework/Mono.Framework/Versions/Current/lib/mono/xbuild-frameworks")) + { + return "/Library/Framework/Mono.Framework/Versions/Current/lib/mono/xbuild-frameworks"; + } + + if (Directory.Exists("/usr/local/lib/mono/xbuild-frameworks")) + { + return "/usr/local/lib/mono/xbuild-frameworks"; + } + + if (Directory.Exists("/usr/lib/mono/xbuild-frameworks")) + { + return "/usr/lib/mono/xbuild-frameworks"; + } + + return null; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs index 523b20eca..ffc95ca0c 100644 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs +++ b/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs @@ -104,8 +104,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution internal static string GetDefaultReferenceAssembliesPath(IRuntimeEnvironment runtimeEnvironment, 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); if (!string.IsNullOrEmpty(referenceAssembliesPath)) { return referenceAssembliesPath; @@ -138,6 +137,5 @@ namespace Microsoft.Extensions.DependencyModel.Resolution programFiles, "Reference Assemblies", "Microsoft", "Framework"); } - } } \ No newline at end of file