CppPilot

MSBuild diagnostic Visual Studio C++

MSB3073 command exited with code

An executable run by MSBuild's Exec task reported an error condition. This can happen before compilation, during a custom step, or after linking. The message names the command and its exit code; inspect that tool's output to find the cause. A custom error-matching expression can also make Exec report failure even when the executable exits with code zero.

Applies toVisual Studio MSBuild C++ projects (.vcxproj)
ExamplesFocused excerpts; required context is stated alongside each example

Visual Studio property-page paths describe MSBuild projects. For CMake, configure the corresponding target or preset. Menu names can vary by Visual Studio version; use the cited reference for your toolset.

Build output
error MSB3073: The command "copy C:\Projects\App\config.json C:\Projects\App\x64\Debug\" exited with code 1.

Causes & corrections

Find the case that matches your build. Each example shows what changes and why.

  1. A path contains spaces.

    Quote every path in the command: copy "$(ProjectDir)config.json" "$(OutDir)".

    Problem

    copy $(ProjectDir)config.json $(OutDir)rem Expanded paths contain spaces

    Correction

    copy "$(ProjectDir)config.json" "$(OutDir)config.json"
    Note 1Quote both paths; an explicit destination filename avoids trailing-separator ambiguity.
    VideoFilmed in Visual Studio: this case fixed by hand, then with CppPilot. English narration, with subtitles in English, French, German, Italian and Spanish.
    Transcript

    MSB3073, the command exited with code 1: fixed by hand, then with CppPilot. Launcher compiles and links, then its post-build event copies app settings.json next to the program.

    The copy fails: MSB3073, code 1. Open Project > Properties, Build Events > Post-Build Event.

    The file name has a space and no quotes: copy reads it as two arguments. Quote each path in the command.

    Build again: the file is copied, and the build succeeds. Now the same error, fixed by CppPilot.

    After the failed build, select the error in the Error List, and click Fix with CppPilot. Click Fix on the MSB3073 card.

    The AI reads the failing command, and quotes both paths of the post-build copy in the project file. CppPilot rebuilds the project to check the fix: the error is resolved.

    CppPilot explains and fixes C++ build errors in Visual Studio.

  2. The command or program is not found (code 9009).

    Use the full path of the program, or a macro such as $(SolutionDir); the event runs in the project folder, not in the solution folder.

    Problem

    pack-assets.exe input.jsonrem Not on PATH: exit code 9009

    Correction

    "$(SolutionDir)tools\pack-assets.exe" "$(ProjectDir)input.json"
    Note 2Use the actual tool location instead of assuming it is on the build machine's PATH.
  3. A copy tool uses nonzero codes for non-failure outcomes.

    robocopy uses codes below 8 for non-failure outcomes. Normalize those to zero while preserving codes of 8 or higher. xcopy uses different codes: 1 means no files were found to copy, and 4 is an initialization error. See Microsoft's robocopy and xcopy reference pages.

    Problem

    robocopy "$(ProjectDir)assets" "$(OutDir)assets" /Erem Files copied; robocopy returns 1rem MSBuild sees a nonzero exit as a failure

    Correction

    robocopy "$(ProjectDir)assets" "$(OutDir)assets" /Eif errorlevel 8 exit /b %errorlevel%exit /b 0
    Note 3In a batch event, keep robocopy failure codes of 8 or higher and normalize its non-failure codes to zero.
  4. The destination file is locked.

    The program or another process still holds it: close it and build again.

    Problem

    Post-build copy -> App.dllAnother process has loaded App.dll

    Correction

    Close the process holding App.dllRun the build event again
    Note 4Release the file lock instead of masking the command's exit code.

Sources and scope

Official references

These links document the compiler, build system, or debugger behavior discussed here. Use the version selector on Microsoft Learn for your toolset. Example blocks are focused excerpts; required headers and build settings are stated alongside them.

In your workspace

Investigate MSB3073 with CppPilot

CppPilot gives the selected AI the diagnostic, relevant code, and project settings for the active configuration. Choose Fix to request a correction, then check the result with a rebuild.

Use your own Codex or Claude account, or optional CppPilot Cloud access. Setup instructions

Visual Studio Marketplace