Skip to content

Fix interactive C# aspire init config collision - #16447

Merged
Adam Ratzman (adamint) merged 4 commits into
microsoft:mainfrom
adamint:dev/adamint/issue-15750
Apr 27, 2026
Merged

Fix interactive C# aspire init config collision#16447
Adam Ratzman (adamint) merged 4 commits into
microsoft:mainfrom
adamint:dev/adamint/issue-15750

Conversation

@adamint

Copy link
Copy Markdown
Member

Description

Fixes interactive aspire init in an empty folder when the user accepts the default C# AppHost language. The language selection is no longer written to local config before the single-file C# template runs, which avoids the aspire.config.json overwrite collision. The single-file AppHost template now records appHost.language so the generated config still has complete AppHost metadata.

Fixes #15750

Validation:

  • dotnet test tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj -- --filter-class "*.InitCommandTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • dotnet build tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Avoid writing local language config before the single-file C# AppHost template runs, and include the C# language metadata in the generated config.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16447

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16447"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an aspire init failure in empty folders when accepting the default C# AppHost language by avoiding a premature aspire.config.json write that caused dotnet new to fail due to conflicting files.

Changes:

  • Stop persisting the prompted language selection before running the single-file C# template; persist only after successful scaffolding where appropriate.
  • Update the aspire-apphost-singlefile template’s aspire.config.json to include appHost.language.
  • Add a unit regression test and a new end-to-end test covering the interactive default-C# aspire init flow.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/Aspire.Cli/Commands/InitCommand.cs Defers language persistence to avoid aspire.config.json overwrite collisions during single-file C# init.
src/Aspire.ProjectTemplates/templates/aspire-apphost-singlefile/aspire.config.json Ensures the single-file AppHost template emits appHost.language in config.
tests/Aspire.Cli.Tests/Commands/InitCommandTests.cs Adds regression coverage for the collision scenario described in #15750.
tests/Aspire.Cli.EndToEnd.Tests/CSharpInitTests.cs Adds interactive E2E coverage to ensure default C# init succeeds and outputs expected files/config.

Comment thread src/Aspire.Cli/Commands/InitCommand.cs Outdated
Comment thread src/Aspire.Cli/Commands/InitCommand.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@radical Ankit Jain (radical) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two suggestions from review — both are about making the fix more self-documenting and robust.

Comment thread src/Aspire.Cli/Commands/InitCommand.cs Outdated
Comment thread src/Aspire.Cli/Commands/InitCommand.cs Outdated
Adam Ratzman (adamint) and others added 2 commits April 25, 2026 13:06
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Handle the URL format prompt before waiting for init completion so the interactive C# init E2E test does not time out after selecting the default language.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@adamint
Adam Ratzman (adamint) enabled auto-merge (squash) April 27, 2026 15:30
@adamint
Adam Ratzman (adamint) merged commit 9330950 into microsoft:main Apr 27, 2026
564 of 567 checks passed
@github-actions github-actions Bot added this to the 13.3 milestone Apr 27, 2026
Nell Shamrell-Harrington (nellshamrell) pushed a commit to nellshamrell/aspire that referenced this pull request May 18, 2026
* Fix interactive C# aspire init config collision

Avoid writing local language config before the single-file C# AppHost template runs, and include the C# language metadata in the generated config.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Avoid redundant init language config writes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Refine init language persistence

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix C# init E2E URL prompt handling

Handle the URL format prompt before waiting for init completion so the interactive C# init E2E test does not time out after selecting the default language.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators May 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running aspire init in empty folder fails

3 participants