dotnet / dotnet/aspnetcore

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

Open
#42,411 1 comment 4 reactions 0 assignees View on GitHub
area-mvc feature-css-isolation feature-runtime-compilation
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] 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"
},
```
6. Run the project again and view source
7. 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](https://github.com/dotnet/aspnetcore/issues/33446):

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.