Skip to content

ASP.NET Core 6 MVC CSS Isolation Breaks When RazorRuntimeCompilation Enabled #42411

@jakenuts

Description

@jakenuts

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Enabling razor runtime compilation in an ASP.NET Core 6 MVC project prevents the CSS Isolation feature from generating css-scope attributes in Layout/View tags.

Expected Behavior

Razor runtime compilation should auto-generate the CSS Isolation attributes similarly to running without runtime compilation.

Steps To Reproduce

  1. In Visual Studio 2022 Professional create a new Asp.Net Core Wep App (Model-View-Controller) project.
  2. Run the project and view source
  3. Confirm tags in _Layout have auto-generated scope attributes and stop debugging
  4. Add the nuget package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 6.0.6
  5. Update the environment variables section in your launchSettings.json file to this
 "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
      },
  1. Run the project again and view source
  2. Confirm that the auto generated scope attributes are no longer injected into the Layout tags

I understand this is probably a very complex problem to solve. But it leaves the developer with the choice of either using CSS Isolation (which is really cool) OR runtime compilation which is crucial for a good ASP.NET development experience.

Thanks,

James

Exceptions (if any)

No response

.NET Version

6.0.31

Anything else?

Reference to closed issue #33446:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-css-isolationThis issue is related to CSS Isolation featurefeature-runtime-compilation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions