Search code examples
c#asp.net-coreblazorstatic-files.net-9.0

Blazor 9 MapStaticAssets with nuget


I have successfully migrated my Blazor 8 app to Blazor 9. It has a few razor libraries, all of them providing static assets. I have managed to get the project to run successfully using project references and using

app.MapStaticAssets();

Now I am trying to create a setup in which I build nuget packages from the razor libraries. The static assets are put into

contentFiles/any/net9.0/wwwroot

of the nuget package. From what i understand, this should be correct. In the client project, I reference them via

<link href="_content/<package>/standard-page-layout.css" rel="stylesheet" />

which works perfectly when i have project references. However, in the case of nuget packges, this setup does not work. Does anyone know what I am missing? Is the path in the nuget correct? Am I missing some config?


Solution

  • It was answered in this thread: https://github.com/dotnet/aspnetcore/issues/60680

    Key is to add explicit statements in .csproj:

    <PropertyGroup>
        ...
        <StaticWebAssetBasePath>_content/RazorClassLibrary1</StaticWebAssetBasePath>
        ...
    </PropertyGroup>
    
    <ItemGroup>
        <None Include="wwwroot\**\*" Pack="true" PackagePath="contentFiles/any/net9.0/wwwroot/" />
    </ItemGroup>