Skip to content
Latchkey

Blazor "MSB4018 ... ApplyCssScopes/BundleScopedCss task failed" in CI

Blazor CSS isolation runs MSBuild tasks that rewrite and bundle scoped .razor.css files. When one of those tasks throws, MSBuild reports MSB4018 with the task name and an inner exception, and the build stops.

What this error means

A Blazor build fails with "error MSB4018: The \"...\" task failed unexpectedly" naming a scoped CSS task such as the one that bundles *.razor.css, followed by an exception stack.

MSBuild
error MSB4018: The "BundleScopedCssFiles" task failed unexpectedly.
System.IO.FileNotFoundException: Could not find file 'obj/.../scopedcss/...'.

Common causes

Stale or partial obj/ scoped CSS artifacts

Leftover intermediate scoped CSS files from a different SDK or a partial checkout confuse the bundling task, which then throws.

An SDK mismatch in the CSS isolation pipeline

A runner SDK band different from the one that generated committed artifacts can fail in the scoped CSS task.

How to fix it

Clean intermediate output and rebuild

  1. Delete the project obj/ and bin/ directories in CI before building.
  2. Run a fresh restore and build so scoped CSS regenerates cleanly.
  3. Confirm obj/ is not committed to the repository.
Terminal
dotnet clean
rm -rf obj bin
dotnet build -c Release

Pin the SDK band with global.json

Use the same SDK band locally and in CI so the CSS isolation tasks behave identically.

global.json
{
  "sdk": { "version": "8.0.400", "rollForward": "latestFeature" }
}

How to prevent it

  • Gitignore bin/ and obj/ so stale scoped CSS never reaches CI.
  • Pin a single SDK band for local and CI builds.
  • Read the inner exception under MSB4018 to find the real cause.

Frequently asked questions

What causes "MSB4018 scoped CSS task failed"?
Leftover intermediate scoped CSS files from a different SDK or a partial checkout confuse the bundling task, which then throws.
How do I fix MSB4018 scoped CSS task failed?
Clean intermediate output and rebuild

Related guides

References

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