From cf134cfc8c19f85210472da7c48c1545f39e906a Mon Sep 17 00:00:00 2001 From: Sarah Oslund Date: Mon, 19 Jul 2021 16:04:53 -0700 Subject: [PATCH] Separate testing code for rid resolution --- src/Cli/dotnet/CommonOptions.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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[] { };