Skip to content

Fix. Creating a Blazor project with a space in its name breaks the styling - #62675

Merged
dariatiurina merged 2 commits into
dotnet:mainfrom
dariatiurina:52196-fix-space-no-styles
Jul 11, 2025
Merged

dariatiurina merged 2 commits into
dotnet:mainfrom
dariatiurina:52196-fix-space-no-styles

Conversation

@dariatiurina

Copy link
Copy Markdown
Contributor

Fix. Creating a Blazor project with a space in its name breaks the styling

Description

  • Added a new StyleBundleName generator to the src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/.template.config/template.json file. This generator uses a regex-based transformation to replace spaces in the project name with underscores for it to be aligned with the sanitized assembly name.
  • Updated the src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/App.razor file to use the dynamically generated StyleBundleName for the stylesheet reference, replacing the previously incorrectly bound value.

Fixes #52196

@dariatiurina dariatiurina self-assigned this Jul 11, 2025
Copilot AI review requested due to automatic review settings July 11, 2025 12:45
@github-actions github-actions Bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jul 11, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that Blazor projects with spaces in their names generate valid style bundle filenames by replacing spaces with underscores and updating the App.razor stylesheet reference accordingly.

  • Added a new StyleBundleName regex generator in the template configuration to sanitize project names.
  • Updated the App.razor component to reference the dynamically generated bundle name.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/.template.config/template.json Introduced StyleBundleName symbol with regex replacement steps.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/App.razor Switched stylesheet link to use StyleBundleName.styles.css.

<link rel="stylesheet" href="@Assets["lib/bootstrap/dist/css/bootstrap.min.css"]" />
##endif*@
<link rel="stylesheet" href="@Assets["app.css"]" />
<link rel="stylesheet" href="@Assets["BlazorWebCSharp.1.styles.css"]" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know what this .1 is for? (Just surprised to see it there)

@javiercn javiercn Jul 11, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I think I found the commit in the history that made this change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My theory is that this is a default name and it is through the whole template project, which will be then replaced with the user's chosen name, because folders are name like that and they get replaced with the RootName.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating a Blazor project with a space in its name breaks the styling

3 participants