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."
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
- Run
dotnet restore(ordotnet buildwhich restores) so package build assets exist. - If you split steps, ensure restore precedes build and shares the same package folder.
- Re-run the build.
dotnet restore
dotnet build --no-restoreMake 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.
<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(...)".