diff --git a/src/Cli/dotnet/CommonOptions.cs b/src/Cli/dotnet/CommonOptions.cs index 8289295733bb..b3b98dab1a73 100644 --- a/src/Cli/dotnet/CommonOptions.cs +++ b/src/Cli/dotnet/CommonOptions.cs @@ -165,7 +165,8 @@ 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"); + // When running under test the path does not always contain "dotnet" and Product.Version is empty. + dotnetRootPath = Path.GetFileName(dotnetRootPath).Contains("dotnet") ? dotnetRootPath : Path.Combine(dotnetRootPath, "dotnet"); var ridFileName = "NETCoreSdkRuntimeIdentifierChain.txt"; string runtimeIdentifierChainPath = string.IsNullOrEmpty(Product.Version) ? Path.Combine(Directory.GetDirectories(Path.Combine(dotnetRootPath, "sdk"))[0], ridFileName) : diff --git a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs index ddac1237a45f..02cb2e7f0ad1 100644 --- a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs +++ b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs @@ -97,7 +97,7 @@ public void ArchOptionCannotBeCombinedWithRuntime() }); } - [Theory] + [WindowsOnlyTheory] [InlineData("build")] [InlineData("publish")] [InlineData("test")] @@ -114,7 +114,7 @@ public void CommandsRunWithOSOption(string command) .Pass(); } - [Theory] + [WindowsOnlyTheory] [InlineData("build")] [InlineData("publish")] [InlineData("test")]