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.
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.
dotnet build -bl:build.binlog
# open build.binlog in the MSBuild Structured Log Viewer to find the failing taskMake the Exec/task report its error
For an Exec, surface stderr and the exit code; for a custom task, log a real error.
<Exec Command="./scripts/gen.sh"
ConsoleToMSBuild="true"
IgnoreExitCode="false" />How to prevent it
- Have custom MSBuild tasks always
Log.LogErroron their failure paths. - Use
ConsoleToMSBuildonExecsteps so command output reaches the log. - Capture a binlog as a CI artifact for tasks that fail without diagnostics.