From cc30cf1acc3c093092e0631b2d273d56c4c4b6db Mon Sep 17 00:00:00 2001 From: Kirill Osenkov Date: Tue, 3 Sep 2024 17:10:53 -0700 Subject: [PATCH 1/3] Always debug RestoreEx when environment variable is set --- .../NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs b/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs index e9d1b2cebdd..2ff02379cea 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs +++ b/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs @@ -95,12 +95,13 @@ public override bool Execute() { try { -#if DEBUG - if (string.Equals(Environment.GetEnvironmentVariable(DebugEnvironmentVariableName), bool.TrueString, StringComparison.OrdinalIgnoreCase)) + string debugEnvironmentVariableName = Environment.GetEnvironmentVariable(DebugEnvironmentVariableName); + if (string.Equals(debugEnvironmentVariableName, bool.TrueString, StringComparison.OrdinalIgnoreCase) || + string.Equals(debugEnvironmentVariableName, "1", StringComparison.OrdinalIgnoreCase)) { Debugger.Launch(); } -#endif + MSBuildLogger logger = new MSBuildLogger(Log); Dictionary globalProperties = GetGlobalProperties(); From bab7101d904a9e94e54f6d18a98dd79ec862e7de Mon Sep 17 00:00:00 2001 From: Kirill Osenkov Date: Fri, 6 Sep 2024 19:15:18 -0700 Subject: [PATCH 2/3] Also allow debugging RestoreTask --- src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs | 6 +++--- .../NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs b/src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs index 8aa0969acf4..43dd1dea160 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs +++ b/src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs @@ -98,13 +98,13 @@ public class RestoreTask : Microsoft.Build.Utilities.Task, ICancelableTask, IDis public override bool Execute() { -#if DEBUG var debugRestoreTask = Environment.GetEnvironmentVariable("DEBUG_RESTORE_TASK"); - if (!string.IsNullOrEmpty(debugRestoreTask) && debugRestoreTask.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrEmpty(debugRestoreTask) && + (debugRestoreTask.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) || debugRestoreTask == "1") { Debugger.Launch(); } -#endif + var log = new MSBuildLogger(Log); NuGet.Common.Migrations.MigrationRunner.Run(); diff --git a/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs b/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs index 2ff02379cea..01a69ee2240 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs +++ b/src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs @@ -95,9 +95,9 @@ public override bool Execute() { try { - string debugEnvironmentVariableName = Environment.GetEnvironmentVariable(DebugEnvironmentVariableName); - if (string.Equals(debugEnvironmentVariableName, bool.TrueString, StringComparison.OrdinalIgnoreCase) || - string.Equals(debugEnvironmentVariableName, "1", StringComparison.OrdinalIgnoreCase)) + string debugEnvironmentVariable = Environment.GetEnvironmentVariable(DebugEnvironmentVariableName); + if (string.Equals(debugEnvironmentVariable, bool.TrueString, StringComparison.OrdinalIgnoreCase) || + string.Equals(debugEnvironmentVariable, "1", StringComparison.OrdinalIgnoreCase)) { Debugger.Launch(); } From 1d04ba6fa1a5aa1f725410f2a061e31e194efa5e Mon Sep 17 00:00:00 2001 From: Kirill Osenkov Date: Fri, 6 Sep 2024 19:24:37 -0700 Subject: [PATCH 3/3] Fix syntax --- src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs b/src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs index 43dd1dea160..4cc74fc8730 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs +++ b/src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs @@ -100,7 +100,7 @@ public override bool Execute() { var debugRestoreTask = Environment.GetEnvironmentVariable("DEBUG_RESTORE_TASK"); if (!string.IsNullOrEmpty(debugRestoreTask) && - (debugRestoreTask.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) || debugRestoreTask == "1") + (debugRestoreTask.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) || debugRestoreTask == "1")) { Debugger.Launch(); }