Warm tip: This article is reproduced from serverfault.com, please click

Why Blazor CSS isolation not adding the link tag to load the bundled css file?

发布于 2020-11-29 06:16:43

I created a Blazor component and an accompanying css file for the css isolation functionality in the WASM project. When the page is rendered, my element is not getting the css style defined in the css file. Upon inspecting the element, I can see the extra b-* attribute applied to it. I can see a MyProject.Client.styles.css file with the extra b-* added in the css file under ...\obj\Debug\net5.0\scopedcss\bundle\MyProject.Client.styles.css. (* is some random characters)

However, I expected that the Blazor build would add a link tag in the Head section so the browser loads this new bundled css file but it's not there. I used Fiddler and verified that no *.styles.css is being loaded by the browser, which is the problem. Already cleared the cache and application.

Am I missing some manual step or a setting for css isolation to add the link tag? I am using .NET 5.0 release version.

Questioner
Tony_Henrich
Viewed
0
Chris Sainty 2020-11-30 05:43:57

You have to add the tag for the bundled CSS file manually to the host page. Blazor does not add this for you.

<link href="MyProjectName.styles.css" rel="stylesheet">