Skip to content
Latchkey

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

  1. Scroll up to the command/script output above the MSB4181 line for the real error.
  2. Run the failing command directly to reproduce and read its full output.
  3. Fix the command and rebuild.

Make the task log its failure

  1. For Exec, set ConsoleToMSBuild="true" and check IgnoreExitCode.
  2. For a custom task, ensure it logs an error before returning false.
  3. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →