cssvisual-studioblazor.net-8.0

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>

Update

When i generate the package in the Package Manager Console with 'dotnet pack' it generates 'LibB.bundle.scp.css' as wanted. The hash is added when package is generated with the command "pack" (DotNetCoreCLI@2) in our Azure-Devops-Pipeline.


Solution

  • It's Fingerprinting assets feature to prevent reusing old versions of files.

    If you want to disable fingerprint of static assets, I suggest you should use .Net9, and use below settings.

    <PropertyGroup>
      <StaticWebAssetFingerprintingEnabled>false</StaticWebAssetFingerprintingEnabled>
      <StaticWebAssetsFingerprintContent>false</StaticWebAssetsFingerprintContent>
    </PropertyGroup>