WorldNeedsRefactoring
WorldNeedsRefactoring

Reputation: 534

Static styles.css issues after renaming Blazor project

If I start a Blazor server from scratch. Then right-click the project and click rename.

All the namespaces change(EditedProjectName.Pages) but the using statements keep the old references(OriginalProjectName.Pages).

This is fairly easy to overcome with Find and replace OriginalProjectName.Pages => replace with => EditedProjectName.Pages

Now the issue. Seemly randomly the site launches without proper css. The same output as I get if I comment out the static CSS in {PROJECT NAME}.styles.css which makes the sidebar etc disappear incorrect blazor index page view

Any idea of how the project name change can cause this issue and how I can solve or troubleshoot it?

Upvotes: 8

Views: 2495

Answers (5)

skotl
skotl

Reputation: 176

For others experience the same problem, I found a solution and documented it over here: Blazor WebAssembly CSS isolation scoped identities doesn't match

In summary; change the modified dates of your base blazor CSS files to force them to be re-transpiled (like Layout/MainLayout.razor.css and Layout/NavMenu.razor.css)

Upvotes: 1

Norman
Norman

Reputation: 3479

Visual Studio Build Menu -> Clean Solution

AND

deleting the bin and obj folders in the project folder finally worked.

Upvotes: 4

Jerrill
Jerrill

Reputation: 398

I was able to get it working while preserving the ability to rename the project by getting the name of the assembly using reflection in my _Host.cshtml file:

<link href="@(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".styles.css")" rel="stylesheet" />

You would also be able to inject it as a singleton configuration in your DI container and inject it into the cshtml file.

Upvotes: 5

Guildenstern70
Guildenstern70

Reputation: 1859

When you rename a Blazor project, be sure to rename also the Razor CSS file bundle, referenced in

/Pages/_Layout.cshtml

as

<!-- Important: these are the razor css'es built at runtime -->
<link href="[Your_Project_Name].styles.css" rel="stylesheet" />

Upvotes: 3

WorldNeedsRefactoring
WorldNeedsRefactoring

Reputation: 534

The issue disappeared when I did a Build|Clean and a Build|Rebuild.

Upvotes: 10

Related Questions