Skip to content

How to reference assets using new Assets[] syntax in RCL? #62847

@Morasiu

Description

@Morasiu

Background

So my goal is to create a simple Blazor WinForms app.

My current project setup:

  • BlazorComponents - RCL (shared between BlazorServer and BlazorDesktop)
  • BlazorServer - just to debug RCL project using browser DevTools
  • BlazorDesktop - WinForms app with Blazor WebView

Currently, I am prototyping, and I've tried

  1. Create a default .Net 9 Blazor Web App with server-side
  2. Create a default .Net 9 RCL project
  3. Remove everything from RCL project
  4. Move wwwroot and Components from BlazorServer to RCL project.

I've made it work, but I have a problem with CSS imports as you can see:

Image

CSS import errors:

Image

My App.razor file:

<html lang="en">

<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <base href="/"/>
    <link rel="stylesheet" href="@Assets["lib/bootstrap/dist/css/bootstrap.min.css"]"/>
    <link rel="stylesheet" href="@Assets["app.css"]"/>
    <link rel="stylesheet" href="@Assets["BlazorServerTest.styles.css"]"/>
    <ImportMap/>
    <link rel="icon" type="image/png" href="favicon.png"/>
    <HeadOutlet/>
</head>

<body>
<Routes/>
<script src="_framework/blazor.web.js"></script>
</body>

</html>
Image

Project to reproduce: https://github.com/Morasiu/BlazorServerTest

So my question is. How can I use new Assets syntax to reference my CSS files?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions