From 4a4c95fc3ef8e27baa3aa928746c3629ad2ed11c Mon Sep 17 00:00:00 2001 From: nohwnd Date: Wed, 2 Sep 2020 16:47:17 +0200 Subject: [PATCH 1/3] Avoid logging >Task returned false but did not log an error.< on test failure --- src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs index df681503ed..c242db4d2a 100644 --- a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs +++ b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs @@ -161,6 +161,10 @@ public override bool Execute() var traceEnabledValue = Environment.GetEnvironmentVariable("VSTEST_BUILD_TRACE"); Tracing.traceEnabled = !string.IsNullOrEmpty(traceEnabledValue) && traceEnabledValue.Equals("1", StringComparison.OrdinalIgnoreCase); + // Avoid logging "Task returned false but did not log an error." on test failure, because we don't + // write MSBuild error. https://github.com/dotnet/msbuild/blob/51a1071f8871e0c93afbaf1b2ac2c9e59c7b6491/src/Framework/IBuildEngine7.cs#L12 + BuildEngine.GetType().GetProperty("AllowFailureWithoutError")?.SetValue(BuildEngine, true); + vsTestForwardingApp = new VSTestForwardingApp(this.VSTestConsolePath, this.CreateArgument()); if (!string.IsNullOrEmpty(this.VSTestFramework)) { From e9432661362db8a31f2fdfd88265484d5ce27903 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Wed, 2 Sep 2020 17:51:25 +0200 Subject: [PATCH 2/3] Add VSTEST_BUILD_DEBUG env var --- .../Tasks/VSTestTask.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs index c242db4d2a..5bd2ed95a6 100644 --- a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs +++ b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs @@ -161,9 +161,26 @@ public override bool Execute() var traceEnabledValue = Environment.GetEnvironmentVariable("VSTEST_BUILD_TRACE"); Tracing.traceEnabled = !string.IsNullOrEmpty(traceEnabledValue) && traceEnabledValue.Equals("1", StringComparison.OrdinalIgnoreCase); + var debugEnabled = Environment.GetEnvironmentVariable("VSTEST_BUILD_DEBUG"); + if (!string.IsNullOrEmpty(debugEnabled) && debugEnabled.Equals("1", StringComparison.Ordinal)) + { + Console.WriteLine("Waiting for debugger attach..."); + + var currentProcess = System.Diagnostics.Process.GetCurrentProcess(); + Console.WriteLine(string.Format("Process Id: {0}, Name: {1}", currentProcess.Id, currentProcess.ProcessName)); + + while (!System.Diagnostics.Debugger.IsAttached) + { + System.Threading.Thread.Sleep(1000); + } + + System.Diagnostics.Debugger.Break(); + } + // Avoid logging "Task returned false but did not log an error." on test failure, because we don't // write MSBuild error. https://github.com/dotnet/msbuild/blob/51a1071f8871e0c93afbaf1b2ac2c9e59c7b6491/src/Framework/IBuildEngine7.cs#L12 - BuildEngine.GetType().GetProperty("AllowFailureWithoutError")?.SetValue(BuildEngine, true); + var allowfailureWithoutError = BuildEngine.GetType().GetProperty("AllowFailureWithoutError"); + allowfailureWithoutError?.SetValue(BuildEngine, true); vsTestForwardingApp = new VSTestForwardingApp(this.VSTestConsolePath, this.CreateArgument()); if (!string.IsNullOrEmpty(this.VSTestFramework)) From 7867f86c242586853ac1228f2ce83a410202ea3b Mon Sep 17 00:00:00 2001 From: nohwnd Date: Wed, 2 Sep 2020 18:01:06 +0200 Subject: [PATCH 3/3] Using namespaces --- src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs index 5bd2ed95a6..2d151decb3 100644 --- a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs +++ b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs @@ -5,7 +5,9 @@ namespace Microsoft.TestPlatform.Build.Tasks { using System; using System.Collections.Generic; + using System.Diagnostics; using System.Linq; + using System.Threading; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Microsoft.TestPlatform.Build.Resources; @@ -166,15 +168,15 @@ public override bool Execute() { Console.WriteLine("Waiting for debugger attach..."); - var currentProcess = System.Diagnostics.Process.GetCurrentProcess(); + var currentProcess = Process.GetCurrentProcess(); Console.WriteLine(string.Format("Process Id: {0}, Name: {1}", currentProcess.Id, currentProcess.ProcessName)); - while (!System.Diagnostics.Debugger.IsAttached) + while (!Debugger.IsAttached) { - System.Threading.Thread.Sleep(1000); + Thread.Sleep(1000); } - System.Diagnostics.Debugger.Break(); + Debugger.Break(); } // Avoid logging "Task returned false but did not log an error." on test failure, because we don't