Skip to content

Out-of-proc builds in a custom .NET Core process are not possible #6782

@jeffkl

Description

@jeffkl

Issue Description

If you write a custom application in .NET Core, use MSBuildLocator to find .NET Core MSBuild, and attempt to do an out-of-process build, then the MSBuild BuildManager will attempt to launch the node as the user's custom application.

Steps to Reproduce

  • Create a custom .NET Core application named Foo.exe
  • Use MSBuildLocator to find MSBuild in .NET Core
  • Build a project with DisableInProcNode set to true

Expected Behavior

MSBuild APIs correctly build project out-of-proc

Actual Behavior

MSBuild APIs attempt to launch an out-of-proc node with Foo.exe instead of MSBuild.exe

Analysis

This is happening because this call:

But GetCurrentHost assumes that MSBuild.exe is the entry application which is not always correct:

private static string GetCurrentHost()
{
#if RUNTIME_TYPE_NETCORE || MONO
if (CurrentHost == null)
{
using (Process currentProcess = Process.GetCurrentProcess())
{
CurrentHost = currentProcess.MainModule.FileName;
}
}
return CurrentHost;
#else
return null;
#endif

In some cases, the current process is not MSBuild.exe.

Instead, this code should use the current dotnet.exe that is running that application and use the MSBuild location which is already done here:

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

There is another bug where we prepend the path to MSBuild.dll twice:

commandLineArgs = "\"" + msbuildLocation + "\" " + commandLineArgs;

But that doesn't seem to break anything as dotnet.exe correctly ignores that it was given two applications to run!

Versions & Configurations

Any version of .NET Core MSBuild

Metadata

Metadata

Assignees

No one assigned

    Labels

    For considerationUsed for items on the backlog to raise them to the top of that list for discussionPartner requestPartner:NuGetbugneeds-designRequires discussion with the dev team before attempting a fix.triaged

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions