Fix DNS-invalid hostnames with underscores in dotnet new templates#64988
Merged
DamianEdwards merged 10 commits intomainfrom Jan 10, 2026
Merged
Fix DNS-invalid hostnames with underscores in dotnet new templates#64988DamianEdwards merged 10 commits intomainfrom
DamianEdwards merged 10 commits intomainfrom
Conversation
Co-authored-by: DamianEdwards <[email protected]>
Co-authored-by: DamianEdwards <[email protected]>
...rojectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/.template.config/template.json
Outdated
Show resolved
Hide resolved
Copilot
AI
changed the title
[WIP] Fix DNS names generated with underscores in dotnet new
Fix DNS-invalid hostnames with underscores in dotnet new templates
Jan 9, 2026
…acement Co-authored-by: DamianEdwards <[email protected]>
DamianEdwards
approved these changes
Jan 9, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes DNS-invalid hostname generation in ASP.NET Core templates by replacing underscores with hyphens to comply with RFC 952/1123 specifications when project names contain dots or other invalid DNS characters.
Key Changes:
- Added custom value form chain (
lowerCaseInvariantWithHyphens) that transforms project names into DNS-compliant hostnames - Created
hostNamederived symbol that applies the transformation and replaces theLocalhostTldHostNamePrefixplaceholder - Updated
launchSettings.jsonfiles to use the new placeholder instead of hardcoded lowercase class names
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/.template.config/template.json |
Added custom value forms and hostName symbol to transform project names into DNS-compliant hostnames |
src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Properties/launchSettings.json |
Replaced hardcoded lowercase hostname with LocalhostTldHostNamePrefix placeholder for both HTTP and HTTPS profiles |
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/.template.config/template.json |
Added custom value forms and hostName symbol to transform project names into DNS-compliant hostnames |
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Properties/launchSettings.json |
Replaced hardcoded lowercase hostname with LocalhostTldHostNamePrefix placeholder for both HTTP and HTTPS profiles |
...ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/.template.config/template.json
Show resolved
Hide resolved
...rojectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/.template.config/template.json
Show resolved
Hide resolved
Co-authored-by: DamianEdwards <[email protected]>
Co-authored-by: DamianEdwards <[email protected]>
src/ProjectTemplates/test/Templates.Tests/EmptyWebTemplateTest.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: DamianEdwards <[email protected]>
DamianEdwards
approved these changes
Jan 9, 2026
BrennanConroy
approved these changes
Jan 9, 2026
...ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Properties/launchSettings.json
Show resolved
Hide resolved
src/ProjectTemplates/test/Templates.Blazor.Tests/BlazorWebTemplateTest.cs
Show resolved
Hide resolved
Co-authored-by: DamianEdwards <[email protected]>
Co-authored-by: DamianEdwards <[email protected]>
Merged
10 tasks
BrennanConroy
approved these changes
Jan 10, 2026
DamianEdwards
added a commit
that referenced
this pull request
Jan 13, 2026
…64988) * Initial plan * Add DNS-safe hostname forms and symbols to templates Co-authored-by: DamianEdwards <[email protected]> * Add trimming of leading/trailing hyphens for DNS-safe hostnames Co-authored-by: DamianEdwards <[email protected]> * Use distinct placeholder LocalhostTldHostNamePrefix for hostname replacement Co-authored-by: DamianEdwards <[email protected]> * Add tests for DNS-compliant hostname generation with --localhost-tld Co-authored-by: DamianEdwards <[email protected]> * Add tests for DNS-compliant hostname generation in Blazor templates Co-authored-by: DamianEdwards <[email protected]> * Move VerifyDnsCompliantHostname to shared Project class Co-authored-by: DamianEdwards <[email protected]> * Fix -n parameter conflict and add tests with numbers in project names Co-authored-by: DamianEdwards <[email protected]> * Refactor DNS hostname tests to use Theory with InlineData Co-authored-by: DamianEdwards <[email protected]> * Fix razorcomponent item test --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: DamianEdwards <[email protected]> Co-authored-by: Damian Edwards <[email protected]>
wtgodbe
pushed a commit
that referenced
this pull request
Jan 14, 2026
…stnames in launch profiles (#65048) * Fix DNS-invalid hostnames with underscores in dotnet new templates (#64988) * Initial plan * Add DNS-safe hostname forms and symbols to templates Co-authored-by: DamianEdwards <[email protected]> * Add trimming of leading/trailing hyphens for DNS-safe hostnames Co-authored-by: DamianEdwards <[email protected]> * Use distinct placeholder LocalhostTldHostNamePrefix for hostname replacement Co-authored-by: DamianEdwards <[email protected]> * Add tests for DNS-compliant hostname generation with --localhost-tld Co-authored-by: DamianEdwards <[email protected]> * Add tests for DNS-compliant hostname generation in Blazor templates Co-authored-by: DamianEdwards <[email protected]> * Move VerifyDnsCompliantHostname to shared Project class Co-authored-by: DamianEdwards <[email protected]> * Fix -n parameter conflict and add tests with numbers in project names Co-authored-by: DamianEdwards <[email protected]> * Refactor DNS hostname tests to use Theory with InlineData Co-authored-by: DamianEdwards <[email protected]> * Fix razorcomponent item test --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: DamianEdwards <[email protected]> Co-authored-by: Damian Edwards <[email protected]> * Add replaceRepeatedHyphens step to template processing and update tests for DNS-compliant hostnames (#65027) Related to #64978 --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: DamianEdwards <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix DNS names with underscores in dotnet new templates
Summary:
Fixed issue where
dotnet newtemplates generate DNS-invalid hostnames with underscores when project names contain dots (e.g.,my.namespace.web→my_namespace_web), violating RFC 952/1123.Changes Made:
LocalhostTldHostNamePrefixfor template replacement-nparameter in test infrastructure-nparameter to avoid conflicts when args already contains-nor--nameTechnical Implementation:
Templates (EmptyWeb & BlazorWeb):
Created
lowerCaseInvariantWithHyphensvalue form chain that:Added
hostNamederived symbol that applies the transform and replacesLocalhostTldHostNamePrefixplaceholderUpdated launchSettings.json to use the distinct placeholder
Test Infrastructure:
Project.csto:-nparameter whenProjectNameis set-nor--nameto avoid conflictsVerifyDnsCompliantHostnamemethod for shared use across test projectsProjectFactoryFixture.CreateProjectaccepting a project nameLocalhostTldconstant toArgConstantsTests Added (EmptyWeb & BlazorWeb):
ConditionalTheorywithInlineDatafor parameterized testing*TemplateLocalhostTld_GeneratesDnsCompliantHostnamescovers all scenarios:my.namespace.*→my-namespace-*(dots to hyphens).StartWithDot→startwithdot(no leading hyphen)EndWithDot.→endwithdot(no trailing hyphen)My..Test__Project→my--test--project(multiple invalid chars)Project123.Test456→project123-test456(numbers preserved per RFC 1123)Refactoring:
VerifyDnsCompliantHostnamefrom individual test classes to sharedProjectclassCompliance:
✅ RFC 952: Hostnames use letters, digits, and hyphens only
✅ RFC 1123: Allows starting with digits, no underscores
✅ No leading/trailing hyphens in generated hostnames
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.