Skip to content

don't prompt for version when --version was supplied#15527

Open
Muckenbatscher wants to merge 7 commits intomicrosoft:mainfrom
Muckenbatscher:add-version-no-prompt
Open

don't prompt for version when --version was supplied#15527
Muckenbatscher wants to merge 7 commits intomicrosoft:mainfrom
Muckenbatscher:add-version-no-prompt

Conversation

@Muckenbatscher
Copy link
Copy Markdown
Contributor

@Muckenbatscher Muckenbatscher commented Mar 24, 2026

Description

When the --version flag is supplied to aspire CLI during aspire add it would previously prompt for the version anyways.
This only happened when the supplied version is not the latest version of the selected integration package.

Now the CLI will search for all existing versions of a package and if a match to the supplied version is found, it will add it to the Apphost without prompting.
If the supplied version is not found in any of the channels the CLI will still prompt for a version bt will suggest the latest version from each of the sources.

The search for nuget versions is done with the dotnet CLI using the --exact-match flag. This will make sure that all the versions that are returned are from the same package.
The search results are cached like before. For this the key was extended to include the "exactMatch" parameter.
(This means that previously cached pacakage searches cause a cache miss now, because they wil generate a different key)

Also adjust BundleNuGetPackageCache to expand the allVersions property returned from aspire-managed to find a version, even if it is not the latest version of the searched integration package.

Fixes #15396
Reverts the workaround PR #15393

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?

…pire add

The interactive flow would be initiated when a package was found but the version passed by the --version flag is not the latest version of the integration nuget package.
Now fetch all the versions for the selected package from all configured channels.
If the CLI supplied version is found in the list of the available versions skip the interactive flow and use the CLI supplied version.
When supplying a version parameter through the CLI handle the cases:
* supplied version is not the latest version found in any channel
* supplied version does not exist in any of the channels
`aspire add redis --version 13.1.2` will not prompt for a version in this E2E CLI test
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 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 -- 15527

Or

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

@Muckenbatscher
Copy link
Copy Markdown
Contributor Author

I felt responsible for a fix because the CPM test that I introduced surfaced the behaviour and caused the CLI E2E tests to fail😀

@Muckenbatscher
Copy link
Copy Markdown
Contributor Author

Muckenbatscher commented Mar 24, 2026

Also just noticed something:
Various testclasses use a TestDotnetCliRunner. For those I had to adjust the SearchPackagesAsyncCallback to take the new parameter exactMatch.
It seems like in the process of doing so I introduced unrelated changes from automatically applying Code Cleanup on Save in Visual Studio. This mostly includes applying the .editorconfig for whitespaces and sorting usings from what I can tell.

Would you prefer for me to alter the affecting commit to not include these changes?
So the actual changes are not polluted?

@Muckenbatscher Muckenbatscher force-pushed the add-version-no-prompt branch from b53e647 to 84b964f Compare March 24, 2026 18:07
@adamint
Copy link
Copy Markdown
Member

adamint commented Mar 24, 2026

Would you prefer for me to alter the affecting commit to not include these changes? So the actual changes are not polluted?

Yes please!

@adamint adamint added the needs-author-action An issue or pull request that requires more info or actions from the author. label Mar 24, 2026
@Muckenbatscher Muckenbatscher force-pushed the add-version-no-prompt branch from 84b964f to 4265b17 Compare March 24, 2026 23:14
@Muckenbatscher
Copy link
Copy Markdown
Contributor Author

Yes please!

I've rebased the affected commits that had these changes in them.
Now the changes in the PR only include the ones relevant to fixing the --version flag for interactive package version selection.

@Muckenbatscher Muckenbatscher changed the title dont't prompt for version when --version was supplied don't prompt for version when --version was supplied Mar 26, 2026
@Muckenbatscher
Copy link
Copy Markdown
Contributor Author

@adamint is any further action required from my side?

@adamint
Copy link
Copy Markdown
Member

adamint commented Mar 29, 2026

@adamint is any further action required from my side?

No, I will review Monday

@Muckenbatscher Muckenbatscher force-pushed the add-version-no-prompt branch 2 times, most recently from 336f5b4 to c55f844 Compare March 29, 2026 21:55
…sion

Instead check the Apphost.csproj and Directory.Packages.props more thoroughly for the expected result.
@Muckenbatscher Muckenbatscher force-pushed the add-version-no-prompt branch from c55f844 to 79a4639 Compare March 29, 2026 21:58
@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.

@Muckenbatscher
Copy link
Copy Markdown
Contributor Author

Is anything happening in the CI environment that would cause dotnet package search Aspire.Hosting.Redis --exact-match to only return the 13.2.0 version, instead of all previous versions found in nuget.org? (for example a special nuget.config)

I removed the explicit -version parameter from the CentralPackageManagementTests in Cli.EndToEnd.Test for now. In its place I added the --non-interactive flag to skip waiting for the intearactive selection flow.
The testcases introduced in AddCommandTests in the Cli.Tests project still cover supplying the --version parameter.

The Bundle use cases includes running in CI and when installing the dogfooding CLI locally.
When running in a bundle use case the call to the aspire-managed executable would not be interpreted correctly to expand the `allVersions` property of the returned json object.
This would cause the same error as previously, where the `--version` was not respected when supplied by the CLI.
@Muckenbatscher
Copy link
Copy Markdown
Contributor Author

I saw that when running a Bundle, a different implementation of the INuGetPackageCache was resolved at runtime. The BundleNuGetPackageCache didn't have the logic implemented yet to iterate all the versions for the selected package.
This has now been added.

The bundle mode is enabled when installing the CLI locally via the dogfooding install script, and therefore also when it is being installed like this in the CI environment.

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

Labels

needs-author-action An issue or pull request that requires more info or actions from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aspire add --version should not prompt for a version

2 participants