Skip to content
Merged
Changes from all 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 @@ -228,6 +228,33 @@ protected IList<NodeContext> GetNodes(
msbuildLocation = _componentHost.BuildParameters.NodeExeLocation;
}

// Extract the expected NodeMode from the command line arguments
NodeMode? expectedNodeMode = NodeModeHelper.ExtractFromCommandLine(commandLineArgs);

#if RUNTIME_TYPE_NETCORE
// When MSBuild is hosted by dotnet.exe (e.g. `dotnet build`), NodeExeLocation may resolve
// to the AppHost (MSBuild.exe on Windows, MSBuild on Unix) because BuildEnvironmentHelper
// prefers the AppHost over MSBuild.dll. Launching worker nodes as MSBuild.exe AppHost
// processes is measurably slower than using dotnet MSBuild.dll. Prefer MSBuild.dll so
// worker nodes are launched via dotnet.exe, matching the parent process.
// This only applies to regular out-of-proc worker nodes (nodemode:1), not task host nodes
// (nodemode:2) which may need the AppHost for COM host object support.
if (expectedNodeMode == NodeMode.OutOfProcNode
&& !String.IsNullOrEmpty(msbuildLocation)
&& Path.GetFileName(msbuildLocation).Equals(Constants.MSBuildExecutableName, StringComparison.OrdinalIgnoreCase))
{
string currentProcessName = Path.GetFileName(EnvironmentUtilities.ProcessPath);
if (currentProcessName?.Equals(Constants.DotnetProcessName, StringComparison.OrdinalIgnoreCase) == true)
Comment thread
YuliiaKovalova marked this conversation as resolved.
{
string dllPath = Path.Combine(Path.GetDirectoryName(msbuildLocation), Constants.MSBuildAssemblyName);
if (File.Exists(dllPath))
{
msbuildLocation = dllPath;
}
Comment thread
YuliiaKovalova marked this conversation as resolved.
}
}
#endif

if (String.IsNullOrEmpty(msbuildLocation))
{
string msbuildExeName = Environment.GetEnvironmentVariable("MSBUILD_EXE_NAME");
Expand All @@ -240,9 +267,6 @@ protected IList<NodeContext> GetNodes(
}

bool nodeReuseRequested = Handshake.IsHandshakeOptionEnabled(nodeLaunchData.Handshake.HandshakeOptions, HandshakeOptions.NodeReuse);

// Extract the expected NodeMode from the command line arguments
NodeMode? expectedNodeMode = NodeModeHelper.ExtractFromCommandLine(commandLineArgs);

// Get all process of possible running node processes for reuse and put them into ConcurrentQueue.
// Processes from this queue will be concurrently consumed by TryReusePossibleRunningNodes while
Expand Down