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:
|
exeName = GetCurrentHost(); |
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
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
Foo.exeDisableInProcNodeset totrueExpected Behavior
MSBuild APIs correctly build project out-of-proc
Actual Behavior
MSBuild APIs attempt to launch an out-of-proc node with
Foo.exeinstead ofMSBuild.exeAnalysis
This is happening because this call:
msbuild/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Line 483 in aac64bb
But GetCurrentHost assumes that MSBuild.exe is the entry application which is not always correct:
msbuild/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Lines 594 to 608 in aac64bb
In some cases, the current process is not MSBuild.exe.
Instead, this code should use the current
dotnet.exethat is running that application and use the MSBuild location which is already done here:msbuild/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Lines 435 to 437 in aac64bb
There is another bug where we prepend the path to MSBuild.dll twice:
msbuild/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Line 484 in aac64bb
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