diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs
index b7d98c179d5..a2849b8b4f7 100644
--- a/src/MSBuild/XMake.cs
+++ b/src/MSBuild/XMake.cs
@@ -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
@@ -482,6 +484,26 @@ private static string GetFriendlyCounterType(PerformanceCounterType type, string
}
}
#endif
+ ///
+ /// Launch debugger if it's requested by environment variable "MSBUILDDEBUGONSTART".
+ ///
+ 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;
+ }
+ }
///
/// Orchestrates the execution of the application, and is also responsible
@@ -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));