Repro Steps
- Build and run https://github.com/mikeharder/nodereuse-waitforexit.
A. Uses msbuild.exe and dotnet.exe from %PATH%.
WaitForExit() works fine with msbuild.exe /m /nr:true.
WaitForExit() deadlocks with dotnet.exe build /m /nr:true.
Root Cause
WaitForExit() has a bug/behavior where it will wait for all child processes to exit if the parent process output is being read asynchronously (https://stackoverflow.com/a/37983587/102052). The workaround is to call WaitForExit(int.MaxValue) instead, which does not wait for the child processes to exit.
Conclusion
I created this issue for MSBuild since the behavior is inconsistent between msbuild.exe and dotnet.exe build. If the only impact of this inconsistency is WaitForExit(), it's probably a low priority to change. However, it could be a symptom of other possible problems with the way dotnet.exe child processes are created.