0

I have a very specific CSS hot reload issue during VS 2022 17.11.4 debugging sessions with my Blazor .NET 8 server app - I think the fine details matter here.

My scoped CSS file appears in the subfolder:

\obj\Debug\net8.0\scopedcss\bundle\MyNamesapce.styles.css

but never anywhere else, e.g. bin.

The .csproj includes these lines:

<TargetFramework>net8.0</TargetFramework>
<EnableScopedCss>true</EnableScopedCss>

App.razor contains:

<link rel="stylesheet" href="/[email protected]" asp-append-version="true" />

Program.cs contains:

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error", createScopeForErrors: true);
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode();

app.Run();

However the only way to get close to hot reload is to use dotnet watch run from the developer PowerShell and even THEN I have to F5 the browser to reload the CSS.

Without using dotnet watch run ... the scoped CSS changes don't get applied at all until stopping and rebuilding/restarting the project.

The file in the obj scopedcss folder DOES change when one of the scoped .razor.css files changes during a debugging runtime - but only if started with dotnet watch run.

Any ideas?

1
  • Can't reproduce the problem on my side, I'm using the VS 2022 Community (64-bit) Version 17.13.2, and the hot reload works well. I suggest you could check the hotReloadEnabled setting in Properties/launchSettings.json file, make sure you are not disable Hot Reload using "hotReloadEnabled" : false, refer to this article. Besides, you could also try to upgrade the VS to version 17.13.2. Commented Mar 10 at 10:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.