Skip to content
Merged
Changes from all 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
38 changes: 24 additions & 14 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ string[] args
int exitCode;
if (Environment.GetEnvironmentVariable(Traits.UseMSBuildServerEnvVarName) == "1")
{
DebuggerLaunchCheck();

// Use the client app to execute build in msbuild server. Opt-in feature.
exitCode = ((s_initialized && MSBuildClientApp.Execute(
#if FEATURE_GET_COMMANDLINE
Expand Down Expand Up @@ -482,6 +484,26 @@ private static string GetFriendlyCounterType(PerformanceCounterType type, string
}
}
#endif
/// <summary>
/// Launch debugger if it's requested by environment variable "MSBUILDDEBUGONSTART".
/// </summary>
private static void DebuggerLaunchCheck()
{
switch (Environment.GetEnvironmentVariable("MSBUILDDEBUGONSTART"))
{
#if FEATURE_DEBUG_LAUNCH
case "1":
Debugger.Launch();
break;
#endif
case "2":
// Sometimes easier to attach rather than deal with JIT prompt
Process currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Waiting for debugger to attach ({currentProcess.MainModule.FileName} PID {currentProcess.Id}). Press enter to continue...");
Console.ReadLine();
break;
}
}

/// <summary>
/// Orchestrates the execution of the application, and is also responsible
Expand All @@ -506,20 +528,8 @@ string[] commandLine
// with our OM and modify and save them. They'll never do this for Microsoft.*.targets, though,
// and those form the great majority of our unnecessary memory use.
Environment.SetEnvironmentVariable("MSBuildLoadMicrosoftTargetsReadOnly", "true");
switch (Environment.GetEnvironmentVariable("MSBUILDDEBUGONSTART"))
{
#if FEATURE_DEBUG_LAUNCH
case "1":
Debugger.Launch();
break;
#endif
case "2":
// Sometimes easier to attach rather than deal with JIT prompt
Process currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Waiting for debugger to attach ({currentProcess.MainModule.FileName} PID {currentProcess.Id}). Press enter to continue...");
Console.ReadLine();
break;
}

DebuggerLaunchCheck();

#if FEATURE_GET_COMMANDLINE
ErrorUtilities.VerifyThrowArgumentLength(commandLine, nameof(commandLine));
Expand Down