Search code examples
cssblazornugetwebassemblyrazor-component-library

Installing an RCL nuget package with static css files, gives me 404 when consumed


I have tried many of different solutions/suggestions found in here, nothing seems to work. It is probably a minor thing, but I just can't see it

For simplicity, I try only focus on ONE css file in the question.

Once the nuget pack is created from the RCL, I pack it and load it into the Nuget Explorer and get this:

enter image description here

So there are static content. Then I add the nuget package to my Blazor WASM project and edit the index.html file:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <base href="/" />

    <!-- 3. party styles -->
    <link rel="stylesheet" media="screen, print" href="_content/JOSTGO.Blazor.ComponentLibrary.Core/css/bootstrap.min.css" />
</head>

<body class="overflow-hidden">
    <div id="app" class="vh-100 vw-100 d-flex flex-row">Loading...</div>
    <div id="blazor-error-ui">
        An unhandled error has occurred.
        <a href="" class="reload">Reload</a>
        <a class="dismiss">🗙</a>
    </div>
    <script src="_framework/blazor.webassembly.js"></script>
</body>

</html>

This is the error I get:

enter image description here

I have not added the builder.WebHost.UseStaticWebAssets() in the host project, in the program file, as some says it is needed, some says it is not. But I have tried it and it made no difference.

I also created a RCL project in the solution to test, where I added a single CSS file. It worked fine.

Let me know if you need more info.


Solution

  • Seems it was a local cache issue. Here is how I fixed it:

    1. Closed Visual Studio
    2. Open a powershell
    3. Run nuget.exe locals all -clear
    4. Go to root folder of the project, still in powershell
    5. Run nuget.exe restore
    6. Reopen solution in VS, build and run.

    Now my css files were referenced correctly.