MSBuild "MSB4181: task returned false but did not log an error" in CI
MSB4181 means a build task reported failure (returned false) without logging a clear error. It most often wraps an Exec task whose command exited non-zero, or a custom task that swallowed its own error - the real failure is in the wrapped command's output above.
What this error means
Build fails with MSB4181 naming the task. The actual cause (a script's non-zero exit, a failed external tool) usually appears just above in the log.
dotnet
error MSB4181: The "Exec" task returned false but did not log an error.Common causes
An Exec command exited non-zero
A shell/script invoked by an Exec task failed, so MSBuild marks the task false even if the command did not surface a tidy error line.
A custom task failed without logging
A custom MSBuild task returned false on an internal failure without calling the logging API.
How to fix it
Surface the wrapped command output
- Scroll up to the command/script output above the MSB4181 line for the real error.
- Run the failing command directly to reproduce and read its full output.
- Fix the command and rebuild.
Make the task log its failure
- For
Exec, setConsoleToMSBuild="true"and checkIgnoreExitCode. - For a custom task, ensure it logs an error before returning false.
- Rebuild with a binlog (
-bl) if still opaque.
.csproj target
<Exec Command="./scripts/gen.sh" ConsoleToMSBuild="true" />How to prevent it
- Have Exec/custom tasks log a clear error on failure.
- Capture a binlog artifact on CI build failures.
- Run wrapped scripts standalone to validate them before the build calls them.
Related guides
MSBuild "MSB4018: The X task failed unexpectedly" in CIFix MSBuild "MSB4018: The X task failed unexpectedly" in CI - a build task threw an unhandled exception, ofte…
C# "CS0006: Metadata file could not be found" in CIFix C# "CS0006: Metadata file X.dll could not be found" in CI - a referenced project failed to build or built…
MSBuild "MSB1011: Specify which project or solution to use" in CIFix MSBuild "MSB1011: Specify which project or solution file to use" in CI - dotnet build or run found multip…