Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2025

Conversation

dariatiurina
Copy link
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 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
Copy link
Contributor

@Copilot Copilot AI left a comment

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.

@@ -10,7 +10,7 @@
<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
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)

Copy link
Member

@javiercn javiercn Jul 11, 2025

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
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.

@dariatiurina dariatiurina merged commit a070501 into dotnet:main Jul 11, 2025
30 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview7 milestone Jul 11, 2025
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
2 participants