MSBuild "MSB4057: target does not exist in the project" in CI
By Kaveh Alemi·Latchkey
MSB4057 means a build invoked a target by name that the project (or its imports) does not define. It is a wiring problem: a typo in the /t: argument, a missing import that should provide the target, or invoking a target on the wrong project.
What this error means
The build fails with MSB4057 naming the missing target. It reproduces deterministically.
dotnet
error MSB4057: The target "PublishContainer" does not exist in the project.
Diagnose it: SDK version and restore first
Most .NET CI failures are an SDK mismatch or a restore that did not happen. global.json pins the SDK, and if the runner does not have that exact version the failure message is about the project rather than the SDK.
Terminal
dotnet --info
cat global.json 2>/dev/null
# restore explicitly so a restore failure is not reported as a build failure
dotnet restore --verbosity normal
dotnet build --no-restore -warnaserror
Common causes
A typo or wrong target name
The /t: (or dotnet msbuild -t:) argument names a target that is spelled wrong or does not apply to this project type.
A missing import that defines the target
The target comes from an SDK or package import that is not referenced, so the target name resolves to nothing.
How to fix it
Use a defined target or add the import
List available targets to confirm the correct name.
Fix the /t: argument, or add the SDK/package that provides the target.
Re-run the build.
shell
dotnet msbuild App.csproj -t:Help # or inspect targets via the build log
How to prevent it
Reference target names from documentation rather than memory.
Keep custom targets in imported .props/.targets that travel with the project.
Frequently asked questions
What causes MSBuild "MSB4057: target does not exist in the project" in CI?
There are 2 common causes: a typo or wrong target name and a missing import that defines the target. The /t: (or dotnet msbuild -t:) argument names a target that is spelled wrong or does not apply to this project type.
How do I fix MSBuild "MSB4057: target does not exist in the project" in CI?
Use a defined target or add the import. List available targets to confirm the correct name.
What does MSBuild "MSB4057: target does not exist in the project" in CI actually mean?
The build fails with MSB4057 naming the missing target.
How do I stop MSBuild "MSB4057: target does not exist in the project" in CI happening again?
Reference target names from documentation rather than memory. The prevention section lists 2 changes that keep it from recurring.