Skip to content
Latchkey

MSBuild "error MSB4019: imported project was not found" in CI

A project (or a NuGet package) imports a .props or .targets file by path, and that file is not present on the runner. MSB4019 prints the exact import path it could not find.

What this error means

dotnet build fails with "error MSB4019: The imported project ".../X.targets" was not found. Confirm that the expression in the Import declaration is correct, and that the file exists on disk."

dotnet
error MSB4019: The imported project "/home/runner/.nuget/packages/some.pkg/1.0.0/build/Some.Pkg.targets"
was not found. Confirm that the expression in the Import declaration "...$(NuGetPackageRoot)..." is correct.

Common causes

Restore did not run before build

A package that supplies the imported .targets was not restored, so its build asset is absent when MSBuild evaluates the import.

A hardcoded or wrong import path

The Import points at a path that exists locally but not in CI (an absolute path, a missing SDK component, or a moved file).

How to fix it

Restore before building

  1. Run dotnet restore (or dotnet build which restores) so package build assets exist.
  2. If you split steps, ensure restore precedes build and shares the same package folder.
  3. Re-run the build.
Terminal
dotnet restore
dotnet build --no-restore

Make the import portable or conditional

Reference imports via MSBuild properties, or guard them with a Condition so a missing optional file does not break the build.

Project.csproj
<Import Project="$(MyTargets)" Condition="Exists('$(MyTargets)')" />

How to prevent it

  • Always restore before build in split-step pipelines.
  • Avoid absolute import paths; use MSBuild properties.
  • Guard optional imports with Condition="Exists(...)".

Frequently asked questions

What causes ""error MSB4019: The imported project ... was not found""?
A package that supplies the imported .targets was not restored, so its build asset is absent when MSBuild evaluates the import.
How do I fix "error MSB4019: The imported project ... was not found"?
Restore before building

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card