Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

blazor

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" />
  • When environment is set to Development, everything works fine
  • Then, I create appsettings.Live.json and set environment to Live, CSS is not generated and HTTP request trying to load this CSS shows 404 Not Found

What am I missing?

like image 448
Anonymous Avatar asked Nov 26 '20 06:11

Anonymous


2 Answers

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

like image 50
Quango Avatar answered Oct 07 '22 09:10

Quango


Adding to @Quango's answer for .NET 6.

Add this line to Program.cs before you build the app:

builder.WebHost.UseStaticWebAssets();
// Add this: ☝
var app = builder.Build();
like image 42
Ash K Avatar answered Oct 07 '22 09:10

Ash K