aspnetcore: Static files not working on Blazor apps using Razor Class Library (RCL)
Describe the bug
Static resources in the “wwwroot” folder of a Razor class library RCL, aren’t deployed correctly. This is causing apps to crash due to the JavaScript interop to throw exception because js files aren’t in place.
To Reproduce
Steps to reproduce the behavior:
- Create a Blazor application (Any server-side or client-side)
- Create a new RCL project.
- Add a reference from the app to the created library
- Add the <RazorClassLibrary1.Component1/> tag to Index.razor.
- Run the app.
Expected behavior
It should render the component with the “background.png” included in the css style of the library.
Screenshots
The background of the component doesn’t appear.
Additional context
Using the latest preview 8
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0-preview8.19405.7" />
</ItemGroup>
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 27 (11 by maintainers)
@arivoir A project reference is no longer sufficient. You also need to add script tags, link tags, etc for the static asset. For example:
I can second this issue, following Microsoft documentation does not provide a successful path to functionality for the RCL.
Steps taken to reproduce and result are the same as @arivoir outlined above.
From the documentation https://docs.microsoft.com/en-us/aspnet/core/blazor/class-libraries?view=aspnetcore-3.0&tabs=visual-studio
And the other documentation page https://docs.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-3.0&tabs=visual-studio
Do you mean this isn’t true?
Yes, I tried copying the files manually in the app and adding the references in _Host.cshtml. It works in server-side Blazor, but not in client-side Blazor.