MSBuild diagnostic Visual Studio C++
MSB6006 exited with code
A tool that MSBuild started, most often the compiler, the linker, or cmd.exe, failed without reporting its error in a form MSBuild understands. The real error is usually in the lines before it in the Output window.
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.
error MSB6006: "CL.exe" exited with code 2.Causes & corrections
Find the case that matches your build. Each example shows what changes and why.
The real error is printed earlier.
Open View > Output, show the Build output, and look for the first error above MSB6006. Set Tools > Options > Projects and Solutions > Build and Run > MSBuild project build output verbosity to Detailed to see more.
Problem
CL.exe: fatal error C1060: compiler is out of heap spaceMSB6006: "CL.exe" exited with code 2Correction
View > Output > BuildInvestigate C1060 before the MSB6006 summaryNote 1The preceding diagnostic usually contains the cause; MSB6006 reports the tool exit. The compiler ran out of memory.
Errors such as C1060 or C1076 before MSB6006 mean memory pressure, often with parallel builds and large templates: lower Maximum concurrent C++ compilations or the
/MPcount, or use the 64-bit toolset.Problem
Many projects compile many files in parallelCL.exe runs out of memoryCorrection
Tools > Options > Projects and SolutionsVC++ Project SettingsLower Maximum concurrent C++ compilationsNote 2Measure memory pressure and reduce concurrency; the right limit depends on the machine and project. A custom build step failed.
For
cmd.exe, the same causes as MSB3073 apply: quote the paths and check the tool it runs.Problem
Custom command: pack-assets.exe input.jsoncmd.exe returns 9009Correction
Custom command:"$(SolutionDir)tools\pack-assets.exe" "$(ProjectDir)input.json"Note 3Check the custom tool's output, working directory, and return code. An antivirus blocks the tool.
Check the security product's detection log. If trusted build tools were blocked, restore or repair them after reviewing the detection, and use a narrowly scoped exception only when appropriate.
Problem
Security software quarantines CL.exeCompiler task cannot completeCorrection
Review the security product's detection logRestore or repair trusted build tools after reviewApply a narrow approved exception only if neededNote 4Confirm a security-product block before changing exclusions; do not broadly exclude the repository.
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 MSB6006 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