diff --git a/src/Microsoft.AspNetCore.Razor.Tools/PipeName.cs b/src/Microsoft.AspNetCore.Razor.Tools/PipeName.cs index 0b897bf05c..b35275816d 100644 --- a/src/Microsoft.AspNetCore.Razor.Tools/PipeName.cs +++ b/src/Microsoft.AspNetCore.Razor.Tools/PipeName.cs @@ -23,11 +23,18 @@ namespace Microsoft.AspNetCore.Razor.Tools // // This is similar to (and based on) the code used by Roslyn in VBCSCompiler: // https://github.com/dotnet/roslyn/blob/c273b6a9f19570a344c274ae89185b3a2b64d93d/src/Compilers/Shared/BuildServerConnection.cs#L528 - public static string ComputeDefault() + public static string ComputeDefault(string toolDirectory = null) { + if (string.IsNullOrEmpty(toolDirectory)) + { + // This can be null in cases where we don't have a way of knowing the tool assembly path like when someone manually + // invokes the cli tool without passing in a pipe name as argument. + toolDirectory = AppDomain.CurrentDomain.BaseDirectory; + } + // Include a prefix so we can't conflict with VBCSCompiler if we somehow end up in the same directory. // That would be a pretty wacky bug to try and unravel. - var baseName = ComputeBaseName("Razor:" + AppDomain.CurrentDomain.BaseDirectory); + var baseName = ComputeBaseName("Razor:" + toolDirectory); // Prefix with username and elevation var isAdmin = false; diff --git a/src/Microsoft.AspNetCore.Razor.Tools/ServerProtocol/ServerConnection.cs b/src/Microsoft.AspNetCore.Razor.Tools/ServerProtocol/ServerConnection.cs index 3f729da331..1c9f122ace 100644 --- a/src/Microsoft.AspNetCore.Razor.Tools/ServerProtocol/ServerConnection.cs +++ b/src/Microsoft.AspNetCore.Razor.Tools/ServerProtocol/ServerConnection.cs @@ -83,19 +83,19 @@ namespace Microsoft.AspNetCore.Razor.Tools public static Task RunOnServer( string pipeName, IList arguments, - ServerPaths buildPaths, + ServerPaths serverPaths, CancellationToken cancellationToken, string keepAlive = null, bool debug = false) { if (string.IsNullOrEmpty(pipeName)) { - pipeName = PipeName.ComputeDefault(); + pipeName = PipeName.ComputeDefault(serverPaths.ClientDirectory); } return RunOnServerCore( arguments, - buildPaths, + serverPaths, pipeName: pipeName, keepAlive: keepAlive, timeoutOverride: null, @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Razor.Tools private static async Task RunOnServerCore( IList arguments, - ServerPaths buildPaths, + ServerPaths serverPaths, string pipeName, string keepAlive, int? timeoutOverride, @@ -119,12 +119,12 @@ namespace Microsoft.AspNetCore.Razor.Tools return new RejectedServerResponse(); } - if (buildPaths.TempDirectory == null) + if (serverPaths.TempDirectory == null) { return new RejectedServerResponse(); } - var clientDir = buildPaths.ClientDirectory; + var clientDir = serverPaths.ClientDirectory; var timeoutNewProcess = timeoutOverride ?? TimeOutMsNewProcess; var timeoutExistingProcess = timeoutOverride ?? TimeOutMsExistingProcess; var clientMutexName = MutexName.GetClientMutexName(pipeName); @@ -175,8 +175,8 @@ namespace Microsoft.AspNetCore.Razor.Tools if (client != null) { var request = ServerRequest.Create( - buildPaths.WorkingDirectory, - buildPaths.TempDirectory, + serverPaths.WorkingDirectory, + serverPaths.TempDirectory, arguments, keepAlive);