diff --git a/src/Cli/dotnet/CommonOptions.cs b/src/Cli/dotnet/CommonOptions.cs index ae2b93e25724..20e89691926f 100644 --- a/src/Cli/dotnet/CommonOptions.cs +++ b/src/Cli/dotnet/CommonOptions.cs @@ -164,12 +164,20 @@ internal static string ResolveRidShorthandOptionsToRuntimeIdentifier(string os, private static string GetCurrentRuntimeId() { - var dotnetRootPath = Path.GetDirectoryName(Environment.ProcessPath); - dotnetRootPath = dotnetRootPath.Contains("dotnet") ? dotnetRootPath : Path.Combine(dotnetRootPath, "dotnet"); + string runtimeIdentifierChainPath; var ridFileName = "NETCoreSdkRuntimeIdentifierChain.txt"; - string runtimeIdentifierChainPath = string.IsNullOrEmpty(Product.Version) ? - Path.Combine(Directory.GetDirectories(Path.Combine(dotnetRootPath, "sdk"))[0], ridFileName) : - Path.Combine(dotnetRootPath, "sdk", Product.Version, ridFileName); + if (Path.GetFileName(Environment.ProcessPath).Equals("dotnet.exe")) + { + var dotnetRootPath = Path.GetDirectoryName(Environment.ProcessPath); + runtimeIdentifierChainPath = Path.Combine(dotnetRootPath, "sdk", Product.Version, ridFileName); + } + else + { + // When testing we run under testhost.exe + var dotnetRootPath = Path.GetDirectoryName(Environment.ProcessPath); + dotnetRootPath = dotnetRootPath.Contains("dotnet") ? dotnetRootPath : Path.Combine(dotnetRootPath, "dotnet"); + runtimeIdentifierChainPath = Path.Combine(Directory.GetDirectories(Path.Combine(dotnetRootPath, "sdk"))[0], ridFileName); + } string[] currentRuntimeIdentifiers = File.Exists(runtimeIdentifierChainPath) ? File.ReadAllLines(runtimeIdentifierChainPath).Where(l => !string.IsNullOrEmpty(l)).ToArray() : new string[] { };