Constrain aspire-starter port replacers to localhost: URLs - #20031
James Newton-King (JamesNK) merged 1 commit into
Conversation
The dynamic port symbols (webHttpPortReplacer, apiServiceHttpPortReplacer,
appHostHttpPortReplacer, etc.) used a bare numeric "replaces" value, so the
template engine substituted that number everywhere in generated content, not
just in launchSettings.json. Since the default ports (5000, 7000, 5301, 7301,
15000, 17000, 19000, 20000, 21000, 22000) also occur as plain numeric literals
in vendored files such as wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js
(e.g. carousel interval: 5000), those files ended up with churned values that
differ between generated projects, making diffs across template runs noisy.
Add "onlyIf": [{"after": "localhost:"}] to each port replacer so substitution
only fires in "localhost:<port>" contexts, matching the fix already applied
upstream for the same class of bug (dotnet/aspnetcore#65165, dotnet/sdk#48811).
Fixes microsoft#20030
|
🚀 Dogfood this PR with:
curl -fsSL https://github.com/@raw/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 20031Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 20031" |
|
@microsoft-github-policy-service agree company="Broadcom" |
There was a problem hiding this comment.
🟡 Changes recommended
The behavioral bug fix lacks automated regression coverage in the existing template test suite.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Constrains Aspire Starter port replacement to localhost URLs, preventing unintended modifications to vendored assets.
Changes:
- Adds
onlyIfconstraints to all ten port replacers. - Preserves unrelated numeric literals such as Bootstrap timing values.
File summaries
| File | Description |
|---|---|
src/Aspire.ProjectTemplates/templates/aspire-starter/.template.config/template.json |
Restricts port substitutions to localhost: contexts. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
James Newton-King (JamesNK)
left a comment
There was a problem hiding this comment.
Reviewed the template replacement behavior. No issues found.
47a0448
into
microsoft:main
|
Thanks! |
|
The CI build failed due to test failure(s) that appear unrelated to the PR changes. These may be flaky tests. Suspected flaky test(s):
Suggested actions:
You can re-run the failed jobs from the workflow run page. |
|
James Newton-King (@JamesNK) Thanks for the review and merge. I would like to backport this PR so that it ships with the next release. Which branch should I target for that? |
|
/backport to release/13.5 |
|
Started backporting to |
|
James Newton-King (@JamesNK) an error occurred while backporting to |
|
/backport to release/13.5 |
|
Started backporting to |
|
James Newton-King (@JamesNK) an error occurred while backporting to |
Description
The dynamic port symbols (
webHttpPortReplacer,apiServiceHttpPortReplacer,appHostHttpPortReplacer, etc.) used a bare numeric "replaces" value, so the template engine substituted that number everywhere in generated content, not just inlaunchSettings.json. Since the default ports (5000, 7000, 5301, 7301, 15000, 17000, 19000, 20000, 21000, 22000) also occur as plain numeric literals in vendored files such aswwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js(e.g. carousel interval: 5000), those files ended up with churned values that differ between generated projects, making diffs across template runs noisy.Add
"onlyIf": [{"after": "localhost:"}]to each port replacer so substitution only fires in "localhost:" contexts, matching the fix already applied upstream for the same class of bug (dotnet/aspnetcore#65165, dotnet/sdk#48811).Fixes #20030
Checklist
<remarks />and<code />elements on your triple slash comments?Manual testing outcome
I tested it by installing both the pre-fix and post-fix versions of the
aspire-startertemplate locally (viadotnet new install, using the global .NET 10 SDK on the machine to avoid needing this repo's pinned .NET 11 RC1 SDK) and generating two projects with deliberately different ports each time.Before the fix (template.json at HEAD~1), generating with
--webHttpPort 5010vs--webHttpPort 5222produced twobootstrap.bundle.jsfiles that differed:This reproduces the exact bug from #20030 — the port number leaking into an unrelated numeric literal in the vendored JS file.
After the fix (current working tree), the same two-port test produced
launchSettings.jsonfiles with the expected different ports (5010vs5222), butbootstrap.bundle.jswas byte-for-byte identical between the two generated projects.That confirms the
onlyIf: [{"after": "localhost:"}]constraint does what it's supposed to: the port substitution now only fires inlocalhost:<port>contexts and no longer corrupts unrelated numeric literals elsewhere in the template output.Note
This PR was produced using Sonnet 5 (effort High) in Claude Code.