6

I have a razor class library and blazor server that consumes this library, each component in RCL has own css, after reading documentation of microsoft ASP.NET Core Blazor CSS isolation I did the following:

  1. In my razor page of blazor server I added my component: <MyComponent />
  2. In _Host page I added link for bundeling: <link href="Blazor.Components.styles.css" rel="stylesheet">.

After running the application I couldn't see the css of MyComponent.

Did I make something wrong? Can you give me some advice?. I read this page that follows the same approach but for Webassembly!.

Thanks.

1 Answer 1

11

Quoting Razor class library (RCL) support docs:

When a Razor class library (RCL) provides isolated styles, the tag's href attribute points to {STATIC WEB ASSET BASE PATH}/{ASSEMBLY NAME}.bundle.scp.css, where the placeholders are:

  • {STATIC WEB ASSET BASE PATH}: The static web asset base path.
  • {ASSEMBLY NAME}: The class library's assembly name.

In the following example:

  • The static web asset base path is _content/ClassLib.
  • The class library's assembly name is ClassLib.

<link href="_content/ClassLib/ClassLib.bundle.scp.css" rel="stylesheet">

In _Host page you should to add something like:

<link href="_content/YourClassLib/YourClassLib.bundle.scp.css" rel="stylesheet">
Sign up to request clarification or add additional context in comments.

7 Comments

by referencing the dll in .NET 6, this does not work, is in _Layout.cshtml <link href="_content/YourClassLib/YourClassLib.bundle.scp.css" rel="stylesheet" /> but, when referencing as project, i do not need to call it manually, it works and i can inspect the file exact in this path Do i need to include something additional to the dll from the RCL?
@Nicwin Did you find a way of doing that in .net 6? I'm currently struggling.
Hi @Robert - no. after another day-Session i decided to wait for some feedback.
Did anyone solve this? I'm running into similar issues.
For .net 8 the docs seem to imply that you would not need to do anything but the CSS isolation for my RCL would not work unless I did this. Is there something I am missing from the docs?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.