Fix TypeScript AppHost generated port ranges - #16629
Conversation
Use a shared AppHost profile port generator for CLI templates, init, and TypeScript AppHost scaffolding so generated dashboard and service profile ports avoid the Windows ephemeral range. Add regression coverage for the generated TypeScript apphost.run.json ports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes TypeScript AppHost scaffolding occasionally generating dashboard/OTLP/resource-service ports in the Windows ephemeral range, which could prevent DCP from binding the dashboard HTTPS proxy and lead to Aspire reporting an unreachable dashboard URL. It centralizes “safe” profile port generation into a shared generator and applies it consistently across CLI templates, aspire init, and TypeScript scaffolding, with a regression test to keep the ports out of the ephemeral range.
Changes:
- Introduced
AppHostProfilePortGenerator(shared source-linked utility) to generate profile ports from known non-ephemeral ranges. - Updated TypeScript AppHost scaffolding, CLI templates, and
aspire initto use the shared port generator. - Added a TypeScript scaffolding regression test that parses
apphost.run.jsonand asserts generated ports remain below the Windows ephemeral range and within the expected bands.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/TypeScriptLanguageSupportTests.cs | Adds a regression test that parses generated apphost.run.json and validates ports are within the safe ranges and below the Windows ephemeral range. |
| src/Shared/AppHostProfilePortGenerator.cs | Adds the shared port-range constants and generator returning an AppHostProfilePorts record struct. |
| src/Aspire.Hosting.CodeGeneration.TypeScript/TypeScriptLanguageSupport.cs | Switches TypeScript scaffold port generation to use AppHostProfilePortGenerator.Generate(...). |
| src/Aspire.Hosting.CodeGeneration.TypeScript/Aspire.Hosting.CodeGeneration.TypeScript.csproj | Source-links the new shared generator into the TypeScript codegen assembly. |
| src/Aspire.Cli/Templating/CliTemplateFactory.cs | Replaces local/random port-range logic with the shared port generator for CLI templates. |
| src/Aspire.Cli/Commands/InitCommand.cs | Uses the shared generator when writing default profiles during thin aspire init. |
| src/Aspire.Cli/Aspire.Cli.csproj | Source-links the new shared generator into the CLI assembly. |
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16629Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16629" |
|
/backport to release/13.3 |
|
Started backporting to |
dafe7db
into
microsoft:main
* Fix TypeScript AppHost generated port ranges Use a shared AppHost profile port generator for CLI templates, init, and TypeScript AppHost scaffolding so generated dashboard and service profile ports avoid the Windows ephemeral range. Add regression coverage for the generated TypeScript apphost.run.json ports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * PR feedback --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Description
Fixes #16626
TypeScript AppHost scaffolding could generate dashboard, OTLP, and resource-service profile ports from a broad range that overlaps the Windows ephemeral port range. When that happened, DCP could fail to bind the configured dashboard HTTPS proxy while Aspire still reported that unreachable URL.
This consolidates the safe AppHost profile port ranges into a shared generator used by CLI templates,
aspire init, and TypeScript AppHost scaffolding. The TypeScript scaffold now uses the same non-ephemeral bands as the other generation paths, and the regression test parses generatedapphost.run.jsonto verify those ports stay out of the Windows ephemeral range.Validation: Not run locally;
restore.cmdwas still installing the local SDK in the background when this PR was created.Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: