From 342cf7949037a17f4bf18a59faf6fcff6a4d25b1 Mon Sep 17 00:00:00 2001 From: Senthil Date: Wed, 20 Apr 2016 16:10:21 -0700 Subject: [PATCH] Determine FX dir using FX_DEPS_FILE --- src/Microsoft.DotNet.Cli.Utils/CoreHost.cs | 3 ++- src/Microsoft.DotNet.Cli.Utils/Muxer.cs | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs b/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs index 6e4640554..341321ac8 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs @@ -28,7 +28,8 @@ namespace Microsoft.DotNet.Cli.Utils { if (_hostDir == null) { - _hostDir = Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location); + var fxDepsFile = Muxer.GetDataFromAppDomain("FX_DEPS_FILE"); + _hostDir = Path.GetDirectoryName(fxDepsFile); } return _hostDir; diff --git a/src/Microsoft.DotNet.Cli.Utils/Muxer.cs b/src/Microsoft.DotNet.Cli.Utils/Muxer.cs index 08e57b9d8..fe0a1fb9d 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Muxer.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Muxer.cs @@ -33,11 +33,24 @@ namespace Microsoft.DotNet.Cli.Utils } } + public static string GetDataFromAppDomain(string propertyName) + { + var appDomainType = typeof(object).GetTypeInfo().Assembly?.GetType("System.AppDomain"); + var currentDomain = appDomainType?.GetProperty("CurrentDomain")?.GetValue(null); + var deps = appDomainType?.GetMethod("GetData")?.Invoke(currentDomain, new[] { propertyName }); + + return deps as string; + } + private bool TryResolveMuxerFromParentDirectories() { - var appBase = new FileInfo(typeof(object).GetTypeInfo().Assembly.Location); - var muxerDir = appBase.Directory?.Parent?.Parent?.Parent; + var fxDepsFile = GetDataFromAppDomain("FX_DEPS_FILE"); + if (string.IsNullOrEmpty(fxDepsFile)) + { + return false; + } + var muxerDir = new FileInfo(fxDepsFile).Directory?.Parent?.Parent?.Parent; if (muxerDir == null) { return false;