Repository navigation
Add --file-based to aspire init - #20004
Conversation
Bypass .NET solution discovery while preserving language selection and existing scaffolding safeguards. Include localized help, documentation, unit coverage, and a CLI end-to-end regression. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a1def9cc-ebd2-4303-bac9-cbcc1c2c0a97
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 20004Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 20004" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The behavior change is narrowly scoped, matches the PR description, and is covered by both unit/snapshot tests and an end-to-end regression scenario.
Review tier: Lite
Findings: None
What changed in this PR
Adds a new aspire init option to force single-file, repo-root C# initialization even when incidental .sln/.slnx files are present, avoiding solution selection prompts and solution-based AppHost scaffolding.
Changes:
- Added
--force-emptytoInitCommandto bypass.NETsolution discovery for C# and always use the single-file skeleton in the working directory. - Added/updated unit + snapshot tests to cover help output and discovery-bypass behavior (including incidental/nested solutions).
- Added an end-to-end test for
--force-emptyand updated CLI README + localized resources for the new help text.
| File | Description |
|---|---|
| src/Aspire.Cli/Commands/InitCommand.cs | Adds and wires --force-empty to skip solution discovery for C# initialization. |
| src/Aspire.Cli/Resources/InitCommandStrings.resx | Adds localized string for the new option description. |
| src/Aspire.Cli/Resources/InitCommandStrings.Designer.cs | Adds strongly-typed accessor for ForceEmptyOptionDescription. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.cs.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.de.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.es.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.fr.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.it.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.ja.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.ko.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.pl.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.pt-BR.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.ru.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.tr.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.zh-Hans.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/Resources/xlf/InitCommandStrings.zh-Hant.xlf | Adds XLIFF entry for the new option description. |
| src/Aspire.Cli/README.md | Documents aspire init --force-empty usage and expected behavior. |
| tests/Aspire.Cli.Tests/Commands/InitCommandTests.cs | Adds/extends coverage for --force-empty (skip discovery, help text, behavior alongside TypeScript and existing-file cases). |
| tests/Aspire.Cli.Tests/TestServices/TestSolutionLocator.cs | Adds a test double to assert solution discovery is not invoked. |
| tests/Aspire.Cli.Tests/Snapshots/InitCommandTests.InitCommand_Help_ShowsForceEmptyOption.verified.txt | Snapshot for updated init --help output including the new option. |
| tests/Aspire.Cli.Tests/Snapshots/InitCommandTests.InitCommand_ForceEmpty_SkipsSolutionDiscovery.verified.txt | Snapshot for the generated single-file AppHost content when discovery is bypassed. |
| tests/Aspire.Cli.EndToEnd.Tests/CSharpInitTests.cs | Adds E2E scenario ensuring --force-empty ignores incidental solutions and still produces a runnable, empty root AppHost. |
Files not reviewed (1)
- src/Aspire.Cli/Resources/InitCommandStrings.Designer.cs: Generated file
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
PR Testing ReportPR Information
Artifact Version Verification
The official dogfood command was used without extra installer flags. The installation completed successfully. The skill's example follow-up binary path, Changes AnalyzedFiles Changed
Change CategoriesCLI behavior, localization/documentation, and tests. No hosting integration, dashboard, project-template, client/component, VS Code extension, or CI infrastructure implementation changes. MethodEach initialization scenario used a fresh temporary directory seeded with only its intended existing files. Using All Runtime checks used Test Scenarios Executed1. Force-empty with root and nested incidental solutionsCoverage: Happy path. Status: PASSED. Seeded a root aspire init --language csharp --non-interactive --suppress-agent-init --force-emptyInitialization succeeded without a solution-selection prompt. The current directory contained the exact empty Evidence: 2. Malformed incidental solutionsCoverage: Negative/boundary. Status: PASSED. Seeded deliberately invalid root Expected outcome: Do not parse or select those files; successfully create an empty C# AppHost and leave them untouched. The generated source and configured path matched scenario 1. Both malformed files remained byte-for-byte unchanged, and no project files were created. Evidence: 3. Preserve an existing AppHost and configurationCoverage: Boundary/overwrite protection. Status: PASSED. Seeded a user-owned Expected outcome: Report that All four files remained byte-for-byte unchanged. The command exited successfully with the existing-file message. As intended by the existing initialization flow, NuGet source setup still ran. Evidence: 4. Omitted flag retains solution-based initializationCoverage: Regression. Status: PASSED. In a fresh directory containing aspire init --language csharp --non-interactive --suppress-agent-initThe command installed the PR template and created Evidence: 5. Explicit false retains solution-based initializationCoverage: Option boundary/regression. Status: PASSED. In a separate fresh directory containing aspire init --language csharp --non-interactive --suppress-agent-init --force-empty falseThe output structure matched scenario 4: a project-based Evidence: 6. TypeScript brownfield selection remains intactCoverage: Language-selection/layout regression. Status: PASSED. Seeded an existing aspire init --language typescript --force-empty --non-interactive --suppress-agent-initThe command created Evidence: 7. Start the force-empty AppHost beside incidental solutionsCoverage: Runtime/end-to-end. Status: PASSED. Started the AppHost generated in scenario 1 through normal discovery: aspire start --format json --non-interactive
aspire describe --apphost /workspace/confirmed/incidental/apphost.cs --format json --non-interactive
aspire stop --apphost /workspace/confirmed/incidental/apphost.cs --non-interactiveThe CLI discovered the root file-based AppHost despite the incidental project and solutions. It reported a running AppHost PID and dashboard URL. The dashboard responded with HTTP 200 after its normal login redirect. The complete resource array was empty. Stop completed successfully. Evidence: 8. Basic new/start/stop smokeCoverage: CLI creation/runtime regression. Status: PASSED. Created a separate fresh project with the installed PR version and explicit PR hive: aspire new aspire-empty --name NewSmoke --output /workspace/confirmed/new-smoke \
--source /workspace/.aspire/hives/pr-20004/packages \
--version 13.6.0-pr.20004.gb9ad0621 --language csharp \
--localhost-tld false --suppress-agent-init --non-interactiveStarted the generated AppHost, confirmed dashboard HTTP 200 after its login redirect, asserted an empty resource array, and stopped it successfully. Evidence: Initial Setup and Harness CorrectionsThese were not PR defects; the final scenarios were rerun in fresh directories after resolving them:
Initial outputs are retained in Summary
Overall ResultPR VERIFIED for the exercised Linux arm64 scenarios. No PR source changes were needed, and the repository working tree remained clean. Scope and Limitations
ArtifactsPaths below are relative to this report:
Cleanup
|
James Newton-King (JamesNK)
left a comment
There was a problem hiding this comment.
1 CLI naming issue: the new option name does not accurately distinguish the file-based AppHost mode it selects.
Clarify that the option selects a file-based AppHost rather than bypassing overwrite protection. Update help, localization, documentation, and unit/E2E coverage. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a1def9cc-ebd2-4303-bac9-cbcc1c2c0a97
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The behavior is comprehensively covered; only a minor help-text grammar correction remains.
Review tier: Balanced
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Aspire.Cli/Resources/InitCommandStrings.resx — Add the missing subject in the option description |
Files not reviewed (1)
- src/Aspire.Cli/Resources/InitCommandStrings.Designer.cs: Generated file
Regenerate translations and the help snapshot with the corrected description. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a1def9cc-ebd2-4303-bac9-cbcc1c2c0a97
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation matches the documented behavior and includes focused unit, snapshot, and end-to-end coverage.
Review tier: Balanced
Findings: None
Issues resolved since last review (1)
| Severity | Finding |
|---|---|
src/Aspire.Cli/Resources/InitCommandStrings.resx — Add the missing subject in the option description View resolved comment |
Files not reviewed (1)
- src/Aspire.Cli/Resources/InitCommandStrings.Designer.cs: Generated file
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
James Newton-King (JamesNK)
left a comment
There was a problem hiding this comment.
Consider whether to add more validation to option
Reject non-C# selections before scaffolding or persisting language preferences. Cover explicit, configured, and prompted selections and preserve behavior when the option is false or omitted. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a1def9cc-ebd2-4303-bac9-cbcc1c2c0a97
Tests selector2 / 99 PR test projects · 4 PR jobs · 1 advisory-only target, from 21 changed files. Selected PR test projects (2 / 99)
Selected PR jobs (4)
Advisory workflow impact (1)
How these were chosen — grouped by what changed📦 affected project 🧪 🧪 🧪 🧪 🧪 Job reasons
Selection computed for commit |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation matches the described behavior and includes focused unit, snapshot, and end-to-end coverage.
Review tier: Balanced
Findings: None
Files not reviewed (1)
- src/Aspire.Cli/Resources/InitCommandStrings.Designer.cs: Generated file
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
Documents the --file-based flag added in microsoft/aspire#20004, which bypasses .NET solution discovery to always scaffold a single-file apphost.cs and requires C#. Co-authored-by: Copilot <[email protected]>
|
Pull request created: #1648
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#1648 targeting Added a documentation update for the new
Note This draft PR needs human review before merging. |
|
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. |
Documents the --file-based flag added in microsoft/aspire#20004, which bypasses .NET solution discovery to always scaffold a single-file apphost.cs and requires C#. Co-authored-by: aspire-repo-bot[bot] <268009190+aspire-repo-bot[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]>

Description
Repositories can contain incidental
.slnor.slnxfiles that causeaspire initto prompt for a solution or scaffold a solution-based AppHost when the user only wants an empty, file-based AppHost at the repository root.Adds
--file-basedto bypass .NET solution discovery entirely and reuse the existing C# single-file scaffold in the current directory. The option requires C#: selecting another language explicitly, through configuration, or at the language prompt fails with a clear error before scaffolding or persisting language selection. Existing-file protection, supporting configuration, and agent setup remain unchanged. Omitting the flag or passing--file-based falsepreserves normal initialization for all languages.User-facing usage
Run from the repository root:
For non-interactive scaffolding without agent setup:
New option in
aspire init --help:Includes localized help, a localized validation error, and a CLI README example.
Validation
InitCommandTestspassed, including explicit, configured, and prompted non-C# rejection; no project/configuration changes on rejection; unchanged behavior with the option false or omitted; discovery bypass; existing-file preservation; and help/skeleton snapshots.FileBasedInitRejectsTypeScriptWithoutChangingFilescovers explicit and configured TypeScript selections and verifies exit code 1, the error message, and unchanged project/configuration files.FileBasedCSharpInitIgnoresIncidentalSolutionspreserves incidental solutions/projects, starts the generated root AppHost, and confirms it has no resources.--force-emptyspelling at commitb9ad0621. It is historical evidence: the option was subsequently renamed to--file-basedand now rejects non-C# selections in response to review feedback.Fixes # (issue)
Checklist
<remarks />and<code />elements on your triple slash comments?