Use tool assembly path for computing default pipe name

This commit is contained in:
Ajay Bhargav Baaskaran 2018-03-23 16:23:26 -07:00
parent adc7184d98
commit 7bc54b99e0
2 changed files with 17 additions and 10 deletions

View File

@ -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;

View File

@ -83,19 +83,19 @@ namespace Microsoft.AspNetCore.Razor.Tools
public static Task<ServerResponse> RunOnServer(
string pipeName,
IList<string> 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<ServerResponse> RunOnServerCore(
IList<string> 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);