Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 7 additions & 4 deletions src/Build/BackEnd/Components/Communications/NodeLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ private string ResolveExecutableName(string msbuildLocation, out bool isNativeAp
isNativeAppHost = false;

#if RUNTIME_TYPE_NETCORE
// If msbuildLocation is a native app host (e.g., MSBuild.exe on Windows, MSBuild on Linux), run it directly.
// Otherwise, use dotnet.exe to run the managed assembly (e.g., MSBuild.dll).
string fileName = Path.GetFileName(msbuildLocation);
isNativeAppHost = fileName.Equals(Constants.MSBuildExecutableName, StringComparison.OrdinalIgnoreCase);
if (!isNativeAppHost)

// Only managed assemblies (.dll) need dotnet.exe as a host.
// All native executables — MSBuild app host, MSBuildTaskHost.exe, etc. — run directly.
if (fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
{
return CurrentHost.GetCurrentHost();
}

// Any .exe or extensionless binary (Linux app host) is a native executable.
isNativeAppHost = true;
#endif
return msbuildLocation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,19 @@ private NodeLaunchData ResolveAppHostOrFallback(
dotnetOverrides);
}

CommunicationsUtilities.Trace("For a host context of {0}, app host not found at {1}, falling back to dotnet.exe from {2}.", hostContext, appHostPath, dotnetHostPath);
// Auto-discover dotnet host path when not explicitly provided.
string resolvedDotnetHostPath = dotnetHostPath;
#if RUNTIME_TYPE_NETCORE
if (string.IsNullOrEmpty(resolvedDotnetHostPath))
{
resolvedDotnetHostPath = CurrentHost.GetCurrentHost();
}
#endif

CommunicationsUtilities.Trace("For a host context of {0}, app host not found at {1}, falling back to dotnet.exe from {2}.", hostContext, appHostPath, resolvedDotnetHostPath);

return new NodeLaunchData(
dotnetHostPath,
resolvedDotnetHostPath,
$"\"{Path.Combine(msbuildAssemblyPath, Constants.MSBuildAssemblyName)}\" {commandLineArgs}",
new Handshake(hostContext, toolsDirectory: msbuildAssemblyPath));
}
Expand Down
17 changes: 13 additions & 4 deletions src/Build/Instance/TaskFactories/TaskHostTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using Microsoft.Build.BackEnd.Logging;
Expand All @@ -13,6 +14,7 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Internal;
using Microsoft.Build.Shared;
using Constants = Microsoft.Build.Framework.Constants;
#if FEATURE_REPORTFILEACCESSES
using Microsoft.Build.Experimental.FileAccess;
using Microsoft.Build.FileAccesses;
Expand Down Expand Up @@ -700,13 +702,20 @@ private void HandleCoresRequest(TaskHostCoresRequest request)
/// </summary>
private void LogErrorUnableToCreateTaskHost(HandshakeOptions requiredContext, string runtime, string architecture, Exception e)
{
string taskHostLocation = NodeProviderOutOfProcTaskHost.GetMSBuildExecutablePathForNonNETRuntimes(requiredContext);
#if NETFRAMEWORK
string taskHostLocation;

if (Handshake.IsHandshakeOptionEnabled(requiredContext, HandshakeOptions.NET))
{
taskHostLocation = NodeProviderOutOfProcTaskHost.GetMSBuildLocationForNETRuntime(requiredContext, _taskHostParameters).MSBuildPath;
(_, string msbuildPath) = NodeProviderOutOfProcTaskHost.GetMSBuildLocationForNETRuntime(requiredContext, _taskHostParameters);
taskHostLocation = msbuildPath != null
? Path.Combine(msbuildPath, Constants.MSBuildExecutableName)
: null;
}
#endif
else
{
taskHostLocation = NodeProviderOutOfProcTaskHost.GetMSBuildExecutablePathForNonNETRuntimes(requiredContext);
}

string msbuildLocation = taskHostLocation ??
// We don't know the path -- probably we're trying to get a 64-bit assembly on a
// 32-bit machine. At least give them the exe name to look for, though ...
Expand Down
Loading