diff --git a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs index c2e9c36bb..e9fdcb99c 100644 --- a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs +++ b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs @@ -56,6 +56,20 @@ namespace Microsoft.DotNet.Tools.Common return path + trailingCharacter; } + public static string EnsureNoTrailingSlash(string path) + { + if (!string.IsNullOrEmpty(path)) + { + char lastChar = path[path.Length - 1]; + if (lastChar == Path.DirectorySeparatorChar || lastChar == '/') + { + path = path.Substring(0, path.Length - 1); + } + } + + return path; + } + public static void EnsureParentDirectory(string filePath) { string directory = Path.GetDirectoryName(filePath); diff --git a/src/Microsoft.DotNet.Compiler.Common/Executable.cs b/src/Microsoft.DotNet.Compiler.Common/Executable.cs index 008e14c1a..b15e8d147 100644 --- a/src/Microsoft.DotNet.Compiler.Common/Executable.cs +++ b/src/Microsoft.DotNet.Compiler.Common/Executable.cs @@ -281,7 +281,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common var additionalProbingPaths = new JArray(); foreach (var packageFolder in _context.LockFile.PackageFolders) { - additionalProbingPaths.Add(packageFolder.Path); + // DotNetHost doesn't handle additional probing paths with a trailing slash + additionalProbingPaths.Add(PathUtility.EnsureNoTrailingSlash(packageFolder.Path)); } runtimeOptions.Add("additionalProbingPaths", additionalProbingPaths); diff --git a/src/Microsoft.DotNet.Core.Build.Tasks/GenerateRuntimeConfigurationFiles.cs b/src/Microsoft.DotNet.Core.Build.Tasks/GenerateRuntimeConfigurationFiles.cs index c53a51363..41dc7e220 100644 --- a/src/Microsoft.DotNet.Core.Build.Tasks/GenerateRuntimeConfigurationFiles.cs +++ b/src/Microsoft.DotNet.Core.Build.Tasks/GenerateRuntimeConfigurationFiles.cs @@ -8,6 +8,7 @@ using System.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.Tools.Common; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Serialization; @@ -119,7 +120,8 @@ namespace Microsoft.DotNet.Cli.Tasks runtimeOptions.AdditionalProbingPaths = new List(); } - runtimeOptions.AdditionalProbingPaths.Add(packageFolder.Path); + // DotNetHost doesn't handle additional probing paths with a trailing slash + runtimeOptions.AdditionalProbingPaths.Add(PathUtility.EnsureNoTrailingSlash(packageFolder.Path)); } } diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index 449192e3a..618f8074f 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -9,6 +9,7 @@ using System.Runtime.InteropServices; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.Tools.Common; using NuGet.Frameworks; namespace Microsoft.DotNet.Tools.Run @@ -152,7 +153,8 @@ namespace Microsoft.DotNet.Tools.Run foreach (var packageFolder in _context.LockFile.PackageFolders) { - hostArgs.Insert(0, packageFolder.Path); + // DotNetHost doesn't handle additional probing paths with a trailing slash + hostArgs.Insert(0, PathUtility.EnsureNoTrailingSlash(packageFolder.Path)); hostArgs.Insert(0, probingPathArg); } }