Skip to content
Latchkey

MSBuild "MSB4181: task returned false but did not log an error"

A build task signaled failure (returned false) without logging an error message, so MSBuild reports MSB4181. The real failure is hidden - often a custom target, an Exec with a non-zero exit, or a generator that swallowed its own error.

What this error means

Build fails with MSB4181 naming the task, but with no preceding error explaining why. It is usually deterministic and points at a custom/third-party task or an Exec step whose command failed quietly.

MSBuild output
error MSB4181: The "Exec" task returned false but did not log an error.

Common causes

An Exec command failed without output

An <Exec> ran a command that exited non-zero but wrote nothing useful to the log, so MSBuild only knows the task returned false.

A custom/third-party task returned false silently

A custom MSBuild task hit a failure path but did not call Log.LogError, so MSBuild surfaces MSB4181 with no detail.

How to fix it

Capture the real failure with a binlog

A binlog shows the failing task’s inputs, command, and any output it did produce.

Terminal
dotnet build -bl:build.binlog
# open build.binlog in the MSBuild Structured Log Viewer to find the failing task

Make the Exec/task report its error

For an Exec, surface stderr and the exit code; for a custom task, log a real error.

.csproj
<Exec Command="./scripts/gen.sh"
      ConsoleToMSBuild="true"
      IgnoreExitCode="false" />

How to prevent it

  • Have custom MSBuild tasks always Log.LogError on their failure paths.
  • Use ConsoleToMSBuild on Exec steps so command output reaches the log.
  • Capture a binlog as a CI artifact for tasks that fail without diagnostics.

Related guides

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