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.
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
- Delete the project
obj/andbin/directories in CI before building. - Run a fresh restore and build so scoped CSS regenerates cleanly.
- Confirm
obj/is not committed to the repository.
dotnet clean
rm -rf obj bin
dotnet build -c ReleasePin the SDK band with global.json
Use the same SDK band locally and in CI so the CSS isolation tasks behave identically.
{
"sdk": { "version": "8.0.400", "rollForward": "latestFeature" }
}How to prevent it
- Gitignore
bin/andobj/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.