Skip to content

Error in InitCommand when solution and project file are in the same directory#14963

Merged
JamesNK merged 2 commits intorelease/13.2from
fix/init-sln-proj-same-dir
Mar 6, 2026
Merged

Error in InitCommand when solution and project file are in the same directory#14963
JamesNK merged 2 commits intorelease/13.2from
fix/init-sln-proj-same-dir

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Mar 5, 2026

Description

When running aspire init, if the solution file and a project file (.csproj, .fsproj, or .vbproj) are in the same directory, the AppHost and ServiceDefaults project directories would be created inside that existing project directory, which is not supported.

This change adds an early validation check in InitCommand.InitializeExistingSolutionAsync that detects this situation and exits with a clear error message telling the user to move the solution file to a parent directory or the project file to a subdirectory.

image

Fixes #14841

Changes:

  • Added validation in InitCommand to check for project files in the solution directory before proceeding
  • Reused DotNetAppHostProject.s_projectExtensions (made internal) for consistent extension matching
  • Added localized error message SolutionAndProjectInSameDirectory to resource files and all xlf translations
  • Added tests for both the error case (all three project types) and the success case

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
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

Copilot AI review requested due to automatic review settings March 5, 2026 02:48
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

🚀 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/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14963

Or

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

Copy link
Contributor

Copilot AI left a comment

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 mode where placing a solution file and a project file in the same directory would cause AppHost/ServiceDefaults to be generated under an existing project directory (an unsupported layout), by adding an early validation with a localized error.

Changes:

  • Added an early guard in InitCommand.InitializeExistingSolutionAsync to detect *.{cs,fs,vb}proj files in the solution directory and exit with a localized error.
  • Reused the .NET project extension list from DotNetAppHostProject by widening its visibility to internal.
  • Added unit tests covering the failure case for .csproj/.fsproj/.vbproj and a “no project files present” success path; added the new localized string to resx + xlf files.

Reviewed changes

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

Show a summary per file
File Description
tests/Aspire.Cli.Tests/Commands/InitCommandTests.cs Adds tests for the new validation guard (error and success scenarios).
src/Aspire.Cli/Commands/InitCommand.cs Adds the early validation check and localized error display.
src/Aspire.Cli/Projects/DotNetAppHostProject.cs Exposes project extensions list as internal for reuse.
src/Aspire.Cli/Resources/InitCommandStrings.resx Adds localized string for the new validation error.
src/Aspire.Cli/Resources/InitCommandStrings.Designer.cs Updates strongly-typed resource accessor for the new string.
src/Aspire.Cli/Resources/xlf/InitCommandStrings.*.xlf Adds the new resource id across translation files.
Files not reviewed (1)
  • src/Aspire.Cli/Resources/InitCommandStrings.Designer.cs: Language not supported

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit cd28d91:

Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AgentInitCommand_WithMalformedMcpJson_ShowsErrorAndExitsNonZero ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndPublishToKubernetes ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateStartWaitAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #22701425017

@JamesNK JamesNK merged commit 55949cd into release/13.2 Mar 6, 2026
385 checks passed
@JamesNK JamesNK deleted the fix/init-sln-proj-same-dir branch March 6, 2026 00:15
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Mar 6, 2026
eerhardt pushed a commit to eerhardt/aspire that referenced this pull request Mar 7, 2026
Copilot AI pushed a commit that referenced this pull request Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants