hi, I have created a new RCL library. (RazorClassLibrary1 .net 9.0)
Component1.razor :
@page "/test1"
<div class="my-component">
This component is defined in the <strong>RazorClassLibrary1</strong> library.
</div>
Component1.razor.css :
.my-component {
border: 2px dashed red;
padding: 1em;
margin: 1em 0;
background-image: url('background.png');
}
Then I created a blazor web app project (server mode).
_Imports.razor :
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using BlazorApp1
@using BlazorApp1.Components
@using RazorClassLibrary1;
App.razor :
<!DOCTYPE html>
<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["app.css"]" />
<link rel="stylesheet" href="@Assets["BlazorApp1.styles.css"]" />
<ImportMap />
<link rel="stylesheet" href="@Assets["RazorClassLibrary1.styles.css"]">
<link rel="stylesheet" href="@Assets["_content/RazorClassLibrary1/RazorClassLibrary1.styles.css"]">
<HeadOutlet @rendermode="InteractiveServer" />
</head>
<body>
<Routes @rendermode="InteractiveServer" />
<script src="_framework/blazor.web.js"></script>
</body>
</html>
Routes.razor:
<Router AppAssembly="typeof(Program).Assembly"
AdditionalAssemblies="new[] {
typeof(RazorClassLibrary1._Imports).Assembly
}">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
Programs.cs:
app.MapRazorComponents<App>()
.AddAdditionalAssemblies(typeof(RazorClassLibrary1._Imports).Assembly)
.AddInteractiveServerRenderMode();
app.Run();
IDE: Microsoft Visual Studio Community 2022 (64 位) - Current 版本 17.14.4
I have copied the RazorClassLibrary1.styles.css file of the released RCL library to wwwroot file.
Why is the style still not displaying correctly?
I didn't set it up somewhere, right? Can you help me? Thank you.