sdk: dotnet test error MSB4181: The "Microsoft.TestPlatform.Build.Tasks.VSTestTask" task returned false but did not log an error

When running NUnit tests using dotnet test I sometimes get the following error at the end of the test run:

C:\Program Files\dotnet\sdk\3.1.401\Microsoft.TestPlatform.targets(32,5): error MSB4181: The "Microsoft.TestPlatform.Build.Tasks.VSTestTask" task returned false but did not log an error. [C:\W ork\Play\TestFailureTest\TestFailureTest.csproj]

This seems to always happen when at least one test failed. I have occasionally seen the same error when all tests pass on our TeamCity build servers, but cannot reproduce that. Output with a failing test, with the attached trivial test project:

C:\W ork\Play\TestFailureTest>dotnet test
Test run for C:\W ork\Play\TestFailureTest\bin\Debug\netcoreapp3.1\TestFailureTest.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.7.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.
  X FailingTest [39ms]
  Error Message:
   This is a test failure message
  Stack Trace:
     at TestFailureTest.Tests.FailingTest() in C:\W ork\Play\TestFailureTest\Tests.cs:line 11


Test Run Failed.
Total tests: 1
     Failed: 1
 Total time: 0.9542 Seconds
C:\Program Files\dotnet\sdk\3.1.401\Microsoft.TestPlatform.targets(32,5): error MSB4181: The "Microsoft.TestPlatform.Build.Tasks.VSTestTask" task returned false but did not log an error. [C:\W ork\Play\TestFailureTest\TestFailureTest.csproj]

Happened both on Windows 7 and on a Linux (Mint 19) VM.

dotnet --info on Windows:

.NET Core SDK (reflecting any global.json):
 Version:   3.1.401
 Commit:    5b6f5e5005

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.401\

Host (useful for support):
  Version: 3.1.7
  Commit:  fcfdef8d6b

.NET Core SDKs installed:
  3.0.100 [C:\Program Files\dotnet\sdk]
  3.1.107 [C:\Program Files\dotnet\sdk]
  3.1.400 [C:\Program Files\dotnet\sdk]
  3.1.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

and on Linux:

.NET Core SDK (reflecting any global.json):
 Version:   3.1.401
 Commit:    39d17847db

Runtime Environment:
 OS Name:     linuxmint
 OS Version:  19
 OS Platform: Linux
 RID:         linuxmint.19-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.401/

Host (useful for support):
  Version: 3.1.7
  Commit:  fcfdef8d6b

.NET Core SDKs installed:
  2.1.809 [/usr/share/dotnet/sdk]
  3.1.401 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.21 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.21 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.21 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

TestFailureTest.zip

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 11
  • Comments: 34 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Everything is red in our CI thanks to this problem. And you cannot expect every company to take risks on RC versions of the next SDK. Any updates on this?

any updates on this? We have the same issue

Tests tend to fail you know. This is how I know someone messed up. The fact that this step fails when tests fails hinders proper reporting afterwards. The CI does not report failed tests but failed builds.

How can i fix the issue?, i can’t wait until the next release this month. My builds are failing in CodeBuild and i don’t know why, I am seeing the same message. Here is the dotnet info:

Running command dotnet --info

.NET Core SDK (reflecting any global.json): Version: 3.1.401 Commit: 39d17847db   Runtime Environment: OS Name: ubuntu OS Version: 18.04 OS Platform: Linux RID: ubuntu.18.04-x64 Base Path: /root/dotnet/sdk/3.1.401/   Host (useful for support): Version: 3.1.7 Commit: fcfdef8d6b

.NET Core SDKs installed: 3.1.401 [/root/dotnet/sdk]   .NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.7 [/root/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.7 [/root/dotnet/shared/Microsoft.NETCore.App]

We have been seeing similar error in our build pipelines. We are using 3.1.402 SDK.

In my case I could fix it by adding NuGet package Microsoft.NET.Test.Sdk to my solution’s test project…

As a workaround, I’ve installed the 3.1.302 SDK and added the following global.json to my project:

{
  "sdk": {
    "version": "3.1.302",
    "rollForward": "disable"
  }
}

MSBuild logs this error when ever a task’s Execute method returns false, but no error has been logged. There are other instances where this can occur as well, e.g. if a task is interrupted/cancelled (https://github.com/dotnet/msbuild/issues/5508).

I did come across a fix in vstest for 16.8 (https://github.com/microsoft/vstest/issues/2384 discusses the issue at length), PR https://github.com/microsoft/vstest/pull/2581/files (this is the issue @loop-evgeny previously mentioned.

From the initial post it seemed 16.7 was being used.

Just want to share that after .Net5 migration everything works again.