css – Disable hash generation in isolated stylesheet filename of razor class libraries in a Blazor Web App


I have a .NET 8 Blazor web app named Contoso which includes Razor class libraries LibA and LibB. LibA is in the same Visual Studio solution, and LibB is in another solution.

When I start the web app, it generates the stylesheet for all libraries on the fly. I can see that in the file https://localhost:0000/Contoso.styles.css that imports all stylesheets with the CSS from the components:

@import '_content/LibA/LibA.bundle.scp.css';
@import '_content/LibB/LibB.ca3u9u6gjt.bundle.scp.css';

All external libraries like LibB have a dynamic token ca3u9u6gjt in the stylesheet name. This changes every time the library is updated and has style changes.

How can I disable this behaviour and remove the hash?

We have to include the filenames directly because some have to be in a correct order. But I don’t want to change the filename after every update. This behaviour is only since Net8.

What did I try so far?

I added this to the .csproj file of the web app and of LibB, but it does not change anything:

<PropertyGroup>
    <CssScopedGenerateSourceHash>false</CssScopedGenerateSourceHash>
</PropertyGroup>

Leave a Reply

Your email address will not be published. Required fields are marked *