Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

using BackendNativeMethods = Microsoft.Build.BackEnd.NativeMethods;
using Task = System.Threading.Tasks.Task;
using DotNetFrameworkArchitecture = Microsoft.Build.Shared.DotNetFrameworkArchitecture;
using Microsoft.Build.Framework;
using Microsoft.Build.BackEnd.Logging;

Expand Down Expand Up @@ -434,9 +433,9 @@ private Process LaunchNode(string msbuildLocation, string commandLineArgs)

// Repeat the executable name as the first token of the command line because the command line
// parser logic expects it and will otherwise skip the first argument
commandLineArgs = msbuildLocation + " " + commandLineArgs;
commandLineArgs = $"\"{msbuildLocation}\" {commandLineArgs}";

BackendNativeMethods.STARTUP_INFO startInfo = new BackendNativeMethods.STARTUP_INFO();
BackendNativeMethods.STARTUP_INFO startInfo = new();
startInfo.cb = Marshal.SizeOf<BackendNativeMethods.STARTUP_INFO>();

// Null out the process handles so that the parent process does not wait for the child process
Expand Down Expand Up @@ -466,11 +465,6 @@ private Process LaunchNode(string msbuildLocation, string commandLineArgs)
creationFlags |= BackendNativeMethods.CREATE_NEW_CONSOLE;
}

BackendNativeMethods.SECURITY_ATTRIBUTES processSecurityAttributes = new BackendNativeMethods.SECURITY_ATTRIBUTES();
BackendNativeMethods.SECURITY_ATTRIBUTES threadSecurityAttributes = new BackendNativeMethods.SECURITY_ATTRIBUTES();
processSecurityAttributes.nLength = Marshal.SizeOf<BackendNativeMethods.SECURITY_ATTRIBUTES>();
threadSecurityAttributes.nLength = Marshal.SizeOf<BackendNativeMethods.SECURITY_ATTRIBUTES>();

CommunicationsUtilities.Trace("Launching node from {0}", msbuildLocation);

string exeName = msbuildLocation;
Expand All @@ -481,7 +475,6 @@ private Process LaunchNode(string msbuildLocation, string commandLineArgs)
{
// Run the child process with the same host as the currently-running process.
exeName = GetCurrentHost();
commandLineArgs = "\"" + msbuildLocation + "\" " + commandLineArgs;
}
#endif

Expand Down Expand Up @@ -526,14 +519,15 @@ private Process LaunchNode(string msbuildLocation, string commandLineArgs)
else
{
#if RUNTIME_TYPE_NETCORE
if (NativeMethodsShared.IsWindows)
{
// Repeat the executable name in the args to suit CreateProcess
commandLineArgs = "\"" + exeName + "\" " + commandLineArgs;
}
// Repeat the executable name in the args to suit CreateProcess
commandLineArgs = $"\"{exeName}\"{commandLineArgs}";
#endif

BackendNativeMethods.PROCESS_INFORMATION processInfo = new BackendNativeMethods.PROCESS_INFORMATION();
BackendNativeMethods.PROCESS_INFORMATION processInfo = new();
BackendNativeMethods.SECURITY_ATTRIBUTES processSecurityAttributes = new();
BackendNativeMethods.SECURITY_ATTRIBUTES threadSecurityAttributes = new();
processSecurityAttributes.nLength = Marshal.SizeOf<BackendNativeMethods.SECURITY_ATTRIBUTES>();
threadSecurityAttributes.nLength = Marshal.SizeOf<BackendNativeMethods.SECURITY_ATTRIBUTES>();

bool result = BackendNativeMethods.CreateProcess
(
Expand Down Expand Up @@ -596,9 +590,18 @@ private static string GetCurrentHost()
#if RUNTIME_TYPE_NETCORE || MONO
if (CurrentHost == null)
{
using (Process currentProcess = Process.GetCurrentProcess())
string dotnetExe = Path.Combine(FileUtilities.GetFolderAbove(BuildEnvironmentHelper.Instance.CurrentMSBuildExePath, 2),
NativeMethodsShared.IsWindows ? "dotnet.exe" : "dotnet");
if (File.Exists(dotnetExe))
{
CurrentHost = dotnetExe;
}
else
{
CurrentHost = currentProcess.MainModule.FileName;
using (Process currentProcess = Process.GetCurrentProcess())
{
CurrentHost = currentProcess.MainModule.FileName;
}
}
}

Expand Down