blazor

Scoped CSS is not auto-generated in Blazor after changing environment


ASP Core 5.0 and VS 2019 Preview 16.9 have CSS scopes feature similar to popular JS frameworks, like Angular. After creating new project, Host.html contains auto-generated CSS.

<link rel="stylesheet" href="MyNameSpace.styles.css" />

What am I missing?


Solution

  • So it appears that the static web assets are only generated in Development mode

    I amended the CreateHostBuilder method in Program.cs accordingly:

    webBuilder.UseStaticWebAssets().UseStartup<Startup>();
    

    This appears to fix it.

    The environments Production and Staging don't seem to need this when the app is published