Skip to content

Commit ef1d067

Browse files
authored
Avoid logging >Task returned false but did not log an error.< (#2557)
* Avoid logging >Task returned false but did not log an error.< on test failure * Add VSTEST_BUILD_DEBUG env var * Using namespaces
1 parent 95cb80f commit ef1d067

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ namespace Microsoft.TestPlatform.Build.Tasks
55
{
66
using System;
77
using System.Collections.Generic;
8+
using System.Diagnostics;
89
using System.Linq;
10+
using System.Threading;
911
using Microsoft.Build.Framework;
1012
using Microsoft.Build.Utilities;
1113
using Microsoft.TestPlatform.Build.Resources;
@@ -161,6 +163,27 @@ public override bool Execute()
161163
var traceEnabledValue = Environment.GetEnvironmentVariable("VSTEST_BUILD_TRACE");
162164
Tracing.traceEnabled = !string.IsNullOrEmpty(traceEnabledValue) && traceEnabledValue.Equals("1", StringComparison.OrdinalIgnoreCase);
163165

166+
var debugEnabled = Environment.GetEnvironmentVariable("VSTEST_BUILD_DEBUG");
167+
if (!string.IsNullOrEmpty(debugEnabled) && debugEnabled.Equals("1", StringComparison.Ordinal))
168+
{
169+
Console.WriteLine("Waiting for debugger attach...");
170+
171+
var currentProcess = Process.GetCurrentProcess();
172+
Console.WriteLine(string.Format("Process Id: {0}, Name: {1}", currentProcess.Id, currentProcess.ProcessName));
173+
174+
while (!Debugger.IsAttached)
175+
{
176+
Thread.Sleep(1000);
177+
}
178+
179+
Debugger.Break();
180+
}
181+
182+
// Avoid logging "Task returned false but did not log an error." on test failure, because we don't
183+
// write MSBuild error. https://github.com/dotnet/msbuild/blob/51a1071f8871e0c93afbaf1b2ac2c9e59c7b6491/src/Framework/IBuildEngine7.cs#L12
184+
var allowfailureWithoutError = BuildEngine.GetType().GetProperty("AllowFailureWithoutError");
185+
allowfailureWithoutError?.SetValue(BuildEngine, true);
186+
164187
vsTestForwardingApp = new VSTestForwardingApp(this.VSTestConsolePath, this.CreateArgument());
165188
if (!string.IsNullOrEmpty(this.VSTestFramework))
166189
{

0 commit comments

Comments
 (0)