Skip to content

Skip version prompt when --version is explicitly specified#16024

Open
mitchdenny wants to merge 1 commit intomainfrom
fix/add-version-no-prompt
Open

Skip version prompt when --version is explicitly specified#16024
mitchdenny wants to merge 1 commit intomainfrom
fix/add-version-no-prompt

Conversation

@mitchdenny
Copy link
Copy Markdown
Member

Description

When aspire add <integration> --version <ver> is used with a version that isn't found in the NuGet search results, the CLI falls into the interactive flow and prompts the user to select a version — even though the version was explicitly specified on the command line. This breaks non-interactive/CI scenarios (e.g., the CPM test).

This PR fixes the issue by skipping the version prompt entirely when --version is explicitly provided. The specified version is passed directly to dotnet add package --version, letting NuGet validate the version in the proper context. If the version doesn't exist, the dotnet add command will fail naturally with an appropriate error.

Changes

  • AddCommand.cs: When --version is specified:
    • count == 1: Skip the interactive flow entirely, take the matched package directly.
    • count > 1: Only prompt for package name disambiguation, skip version prompt.
    • count == 0: Show all packages for name selection, skip version prompt.
    • Override PackageVersion with the CLI-specified version.
  • AddCommandTests.cs: Added two new tests:
    • Version not in search results with single match → no prompt, CLI version used.
    • Version not in search results with multiple name matches → name prompt only, no version prompt.

Fixes #15396

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 April 10, 2026 02:21
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 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/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16024

Or

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

Copy link
Copy Markdown
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 a CLI usability/CI reliability issue where aspire add <integration> --version <ver> could fall into an interactive version-selection prompt when the requested version isn’t present in NuGet search results, instead of passing the explicit version through to dotnet add package --version.

Changes:

  • Update AddCommand package-selection flow to skip the version prompt when --version is explicitly provided and always pass that version through to the add operation.
  • Add unit tests covering “explicit version not in search results” for both single-package and multi-package match scenarios.

Reviewed changes

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

File Description
src/Aspire.Cli/Commands/AddCommand.cs Skips version prompting when --version is provided and uses the CLI-specified version for the add operation.
tests/Aspire.Cli.Tests/Commands/AddCommandTests.cs Adds tests ensuring no version prompt occurs when an explicit version is provided but not found in search results.

@github-actions
Copy link
Copy Markdown
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

@mitchdenny mitchdenny force-pushed the fix/add-version-no-prompt branch from 3461440 to fc09d80 Compare April 10, 2026 04:05
@github-actions
Copy link
Copy Markdown
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

@JamesNK
Copy link
Copy Markdown
Member

JamesNK commented Apr 10, 2026

What happens if a version is specified that doesn't exist?

@mitchdenny mitchdenny force-pushed the fix/add-version-no-prompt branch from fc09d80 to 0538f14 Compare April 10, 2026 04:51
When 'aspire add --version <ver>' is used, skip the interactive version
prompt entirely and pass the specified version directly to 'dotnet add
package --version'. If the version doesn't exist, the dotnet add command
will fail naturally with proper NuGet context.

Previously, if the specified version wasn't found in the NuGet search
results, the CLI would fall into the interactive flow and prompt the
user for a version, breaking non-interactive/CI scenarios.

Fixes #15396

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mitchdenny mitchdenny force-pushed the fix/add-version-no-prompt branch from 0538f14 to ba5b813 Compare April 10, 2026 05:00
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 56 recordings uploaded (commit ba5b813)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AddPackageWithNonExistentVersionFailsGracefully ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AllPublishMethodsBuildDockerImages ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ 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
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ 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

📹 Recordings uploaded automatically from CI run #24227236753

@mitchdenny
Copy link
Copy Markdown
Member Author

What happens if a version is specified that doesn't exist?

This is what it looks like presently: https://asciinema.org/a/ukUigAtJuG9R3dPB

It's pretty ugly, but at the same time when something like this does go wrong and you don't want to offer an interactive picker the diagnostic information is useful. However it is a lot of .NET-ism to drop on people too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aspire add --version should not prompt for a version

3 participants