Constrain aspire-starter port replacers to localhost: URLs - #20031
Constrain aspire-starter port replacers to localhost: URLs#20031Bart Koelman (bart-vmware) wants to merge 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://raw.githubusercontent.com/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
| "onlyIf": [{ | ||
| "after": "localhost:" | ||
| }] |
There was a problem hiding this comment.
I decided to test only manually because the upstream fix didn't add tests either. Please let me know when adding an automated test is a prerequisite to get this merged.
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.