Repository navigation
Fix. Creating a Blazor project with a space in its name breaks the styling - #62675
Conversation
There was a problem hiding this comment.
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
StyleBundleNameregex 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"]" /> |
There was a problem hiding this comment.
Do we know what this .1 is for? (Just surprised to see it there)
There was a problem hiding this comment.
Nevermind, I think I found the commit in the history that made this change.
There was a problem hiding this comment.
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.
Fix. Creating a Blazor project with a space in its name breaks the styling
Description
StyleBundleNamegenerator to thesrc/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/.template.config/template.jsonfile. 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.src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/App.razorfile to use the dynamically generatedStyleBundleNamefor the stylesheet reference, replacing the previously incorrectly bound value.Fixes #52196