Probe for .NET reference assemblies path
This commit is contained in:
parent
2922251444
commit
dc7bab9e28
3 changed files with 62 additions and 4 deletions
|
@ -8,6 +8,7 @@ using System.Linq;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Microsoft.DotNet.ProjectModel.Utilities;
|
using Microsoft.DotNet.ProjectModel.Utilities;
|
||||||
|
using Microsoft.Extensions.DependencyModel.Resolution;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
|
||||||
public static string GetDefaultReferenceAssembliesPath()
|
public static string GetDefaultReferenceAssembliesPath()
|
||||||
{
|
{
|
||||||
// Allow setting the reference assemblies path via an environment variable
|
// 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))
|
if (!string.IsNullOrEmpty(referenceAssembliesPath))
|
||||||
{
|
{
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -104,8 +104,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
|
||||||
internal static string GetDefaultReferenceAssembliesPath(IRuntimeEnvironment runtimeEnvironment, IEnvironment environment)
|
internal static string GetDefaultReferenceAssembliesPath(IRuntimeEnvironment runtimeEnvironment, IEnvironment environment)
|
||||||
{
|
{
|
||||||
// Allow setting the reference assemblies path via an environment variable
|
// 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))
|
if (!string.IsNullOrEmpty(referenceAssembliesPath))
|
||||||
{
|
{
|
||||||
return referenceAssembliesPath;
|
return referenceAssembliesPath;
|
||||||
|
@ -138,6 +137,5 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
|
||||||
programFiles,
|
programFiles,
|
||||||
"Reference Assemblies", "Microsoft", "Framework");
|
"Reference Assemblies", "Microsoft", "Framework");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue