Skip to content
Latchkey

MSBuild "MSB3073: command exited with code N" in CI

MSB3073 reports that a command MSBuild ran (a pre/post-build event or an Exec step) exited non-zero, so the build fails. The non-zero exit is the symptom - the real error is in that command's own output, which appears just before the MSB3073 line.

What this error means

Build fails with MSB3073 quoting the command and its exit code. The command's stdout/stderr above usually contains the actual failure.

dotnet
error MSB3073: The command "npm run build" exited with code 1.

Common causes

A pre/post-build command failed on the runner

A build event runs an external command (npm, a shell script, a tool) that exited non-zero in CI, often due to a missing dependency or environment difference.

The command behaves differently in CI

Paths, env vars, or tool versions differ on the runner, so a command that works locally fails there.

How to fix it

Read the failing command output

  1. Look at the command's own output just above the MSB3073 line.
  2. Run the command directly on a comparable environment to reproduce.
  3. Fix the underlying failure and rebuild.

Make the command CI-safe

  1. Ensure required tools/deps are installed before the build event runs.
  2. Use absolute or workspace-relative paths and required env vars.
  3. Rebuild.

How to prevent it

  • Install tools a build event needs earlier in the CI job.
  • Keep build-event commands portable across local and CI.
  • Move complex steps into explicit, separately-logged CI steps.

Related guides

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