From 724538aff3ca6fa9f884a12d20d2aa07ddfbe4f9 Mon Sep 17 00:00:00 2001 From: Bart Koelman <104792814+bart-vmware@users.noreply.github.com> Date: Thu, 10 Sep 2026 12:04:26 +0200 Subject: [PATCH] Constrain aspire-starter port replacers to localhost: URLs 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:" contexts, matching the fix already applied upstream for the same class of bug (dotnet/aspnetcore#65165, dotnet/sdk#48811). Fixes #20030 --- .../.template.config/template.json | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/Aspire.ProjectTemplates/templates/aspire-starter/.template.config/template.json b/src/Aspire.ProjectTemplates/templates/aspire-starter/.template.config/template.json index e1dff206598..fb8152ea90f 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-starter/.template.config/template.json +++ b/src/Aspire.ProjectTemplates/templates/aspire-starter/.template.config/template.json @@ -184,7 +184,10 @@ "sourceVariableName": "appHostHttpPort", "fallbackVariableName": "appHostHttpPortGenerated" }, - "replaces": "15000" + "replaces": "15000", + "onlyIf": [{ + "after": "localhost:" + }] }, "appHostOtlpHttpPort": { "type": "parameter", @@ -206,7 +209,10 @@ "sourceVariableName": "appHostOtlpHttpPort", "fallbackVariableName": "appHostOtlpHttpPortGenerated" }, - "replaces": "19000" + "replaces": "19000", + "onlyIf": [{ + "after": "localhost:" + }] }, "appHostResourceHttpPort": { "type": "parameter", @@ -228,7 +234,10 @@ "sourceVariableName": "appHostResourceHttpPort", "fallbackVariableName": "appHostResourceHttpPortGenerated" }, - "replaces": "20000" + "replaces": "20000", + "onlyIf": [{ + "after": "localhost:" + }] }, "appHostHttpsPort": { "type": "parameter", @@ -250,7 +259,10 @@ "sourceVariableName": "appHostHttpsPort", "fallbackVariableName": "appHostHttpsPortGenerated" }, - "replaces": "17000" + "replaces": "17000", + "onlyIf": [{ + "after": "localhost:" + }] }, "appHostOtlpHttpsPort": { "type": "parameter", @@ -272,7 +284,10 @@ "sourceVariableName": "appHostOtlpHttpsPort", "fallbackVariableName": "appHostOtlpHttpsPortGenerated" }, - "replaces": "21000" + "replaces": "21000", + "onlyIf": [{ + "after": "localhost:" + }] }, "appHostResourceHttpsPort": { "type": "parameter", @@ -294,7 +309,10 @@ "sourceVariableName": "appHostResourceHttpsPort", "fallbackVariableName": "appHostResourceHttpsPortGenerated" }, - "replaces": "22000" + "replaces": "22000", + "onlyIf": [{ + "after": "localhost:" + }] }, "webHttpPort": { "type": "parameter", @@ -316,7 +334,10 @@ "sourceVariableName": "webHttpPort", "fallbackVariableName": "webHttpPortGenerated" }, - "replaces": "5000" + "replaces": "5000", + "onlyIf": [{ + "after": "localhost:" + }] }, "webHttpsPort": { "type": "parameter", @@ -338,7 +359,10 @@ "sourceVariableName": "webHttpsPort", "fallbackVariableName": "webHttpsPortGenerated" }, - "replaces": "7000" + "replaces": "7000", + "onlyIf": [{ + "after": "localhost:" + }] }, "apiServiceHttpPort": { "type": "parameter", @@ -360,7 +384,10 @@ "sourceVariableName": "apiServiceHttpPort", "fallbackVariableName": "apiServiceHttpPortGenerated" }, - "replaces": "5301" + "replaces": "5301", + "onlyIf": [{ + "after": "localhost:" + }] }, "apiServiceHttpsPort": { "type": "parameter", @@ -382,7 +409,10 @@ "sourceVariableName": "apiServiceHttpsPort", "fallbackVariableName": "apiServiceHttpsPortGenerated" }, - "replaces": "7301" + "replaces": "7301", + "onlyIf": [{ + "after": "localhost:" + }] }, "skipRestore": { "type": "parameter",