Matched signals
- error MSB
- MSB4006
- MSB3644
- MSB4018
- MSB6006
- MSB3027
- MSB3491
- MSB1003
MSBuild task or target failure
What this failure means
MSBuild exited with a fatal error MSBxxxx diagnostic. The task or target
could not complete and the build cannot proceed until the root cause is
resolved.
Symptoms
Faultline looks for one or more of these log fragments:
error MSB
MSB4006
MSB3644
MSB4018
MSB6006
MSB3027
MSB3491
MSB1003
Diagnosis
MSBuild emitted a structured error (error MSBxxxx) from a task or target.
Common causes include:
- MSB4006 — circular dependency in the target dependency graph (e.g.
a project referencing itself or two projects referencing each other through
the
_GenerateRestoreProjectPathWalktarget) - MSB3644 / MSB3270 — reference assemblies for the requested target framework are missing or the processor architecture of a reference does not match the build output
- MSB4018 — an MSBuild task threw an unhandled exception; the stack trace appears immediately below the error line
- MSB6006 — a spawned tool (compiler, linker, custom task) returned a non-zero exit code
- MSB3027 / MSB3491 — the build could not copy or write an output file, usually because it is locked by another process or the output path does not exist
- MSB1003 — no project or solution file found; the working directory or
DOTNET_PROJECT_DIRis wrong
Fix steps
- Read the full
error MSBxxxxline in the log — the four-digit code pinpoints the category. Look the code up in the MSBuild error reference. - For MSB4006 (circular dependency):
- Open the
.csproj/.vbproj/.fsprojfile named in the error. - Check
<ProjectReference>items for cycles (A → B → A). - Check custom
<Target>elements whoseDependsOnTargetsorBeforeTargets/AfterTargetsattributes create a cycle. - Remove or break the cycle; use a shared library project to hold shared code instead of mutual references.
- Open the
- For MSB3644 (missing reference assemblies):
- Verify
<TargetFramework>in the.csprojmatches an SDK installed in the CI image. - Pin the SDK version in
global.jsonand update the CI image to match.
- Verify
- For MSB4018 (task threw exception):
- Read the stack trace that follows the error line.
- If the failing task is a NuGet task, see the
dotnet-restoreplaybook. - If the failing task is a custom task, rebuild or update the task assembly.
- For MSB6006 (tool returned non-zero):
- The real compile or link error will appear above the MSB6006 line — scroll up to find it.
- For MSB3027 / MSB3491 (file copy / write failure):
- Check whether another process is holding the output file.
- Ensure the output directory exists and the runner has write permission.
- For MSB1003 (project not found):
- Confirm the working directory in the CI step matches where the
.slnor.csprojlives. - Check
DOTNET_PROJECT_DIRif the pipeline sets it.
- Confirm the working directory in the CI step matches where the
- Run
dotnet build --verbosity detailedlocally to reproduce with full task-level output.
Validation
dotnet build(ordotnet restore && dotnet build) completes with exit code 0 and noerror MSBlines in the output.- The CI step that previously failed now exits zero.
Why it matters
MSBuild errors surface as the immediate cause shown in CI logs but the four-digit code is the fastest path to the actual fix. Without matching on the structured code, the failure can be misread as a generic restore or compile error, leading to the wrong remediation path.
Prevention
- Set
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>inDirectory.Build.propsto catch target and reference issues locally before they reach CI. - Enforce
<TargetFramework>consistency with aglobal.json-pinned SDK version and a matching CI image. - Periodically audit
<ProjectReference>graphs withdotnet-proj-ref-graphor a custom MSBuild logger to detect incipient cycles before they are committed.
Try it locally
dotnet build --verbosity detailed
dotnet build
How Faultline detects it
Use faultline explain msbuild-error to see the full playbook.
faultline analyze build.log
faultline explain msbuild-error
Generated from playbooks/bundled/log/build/msbuild-error.yaml. Do not edit directly.