Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
9 changes: 9 additions & 0 deletions src/Build.UnitTests/BackEnd/DebugUtils_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.Debugging;
using Shouldly;
using Xunit;

Expand Down Expand Up @@ -38,5 +39,13 @@ public void DumpExceptionToFileShouldWriteInDebugDumpPath()
File.Delete(exceptionFile);
}
}

[Fact]
public void IsInTaskHostNode_ReturnsFalseForCentralNode()
{
// When running in the main test process (no /nodemode argument),
// we should not be in a TaskHost node
DebugUtils.IsInTaskHostNode().ShouldBeFalse();
}
}
}
7 changes: 7 additions & 0 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,13 @@ private static void DebuggerLaunchCheck()
case "1":
Debugger.Launch();
break;
case "3":
// Value "3" debugs the main MSBuild process but skips debugging child TaskHost processes
if (!DebugUtils.IsInTaskHostNode())
{
Debugger.Launch();
}
break;
#endif
case "2":
// Sometimes easier to attach rather than deal with JIT prompt
Expand Down
4 changes: 4 additions & 0 deletions src/MSBuildTaskHost/OutOfProcTaskHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ internal static ExitType Execute()

Console.ReadLine();
break;
case "3":
// Value "3" skips debugging for TaskHost processes but debugs the main MSBuild process
// This is useful when you want to debug MSBuild but not the child TaskHost processes
break;
}

bool restart = false;
Expand Down
10 changes: 10 additions & 0 deletions src/Shared/Debugging/DebugUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ private static bool CurrentProcessMatchesDebugName()

public static string DebugPath { get; private set; }

/// <summary>
/// Returns true if the current process is an out-of-proc TaskHost node.
/// </summary>
/// <returns>
/// True if this process was launched with /nodemode:2 (indicating it's a TaskHost process),
/// false otherwise. This is useful for conditionally enabling debugging or other behaviors
/// based on whether the code is running in the main MSBuild process or a child TaskHost process.
/// </returns>
public static bool IsInTaskHostNode() => ProcessNodeMode.Value == NodeMode.OutOfProcTaskHostNode;

public static string FindNextAvailableDebugFilePath(string fileName)
{
var extension = Path.GetExtension(fileName);
Expand Down
Loading