Problem
When running the aspire new or aspire add commands on a machine that is offline (without an internet connection), the CLI currently attempts to prompt the user to select from a list of available template versions or packages. Since no templates/packages are available offline, this results in an unhandled exception and stack trace similar to:
Unhandled exception: System.InvalidOperationException: Cannot show an empty selection prompt. Please call the AddChoice() method to configure the prompt.
at Spectre.Console.ListPrompt`1.Show(ListPromptTree`1 tree, Func`2 converter, SelectionMode selectionMode, Boolean skipUnselectableItems, Boolean searchEnabled, Int32 requestedPageSize, Boolean wrapAround, CancellationToken cancellationToken) in /_/src/Spectre.Console/Prompts/List/ListPrompt.cs:line 47
at Spectre.Console.SelectionPrompt`1.ShowAsync(IAnsiConsole console, CancellationToken cancellationToken) in /_/src/Spectre.Console/Prompts/SelectionPrompt.cs:line 103
at Aspire.Cli.Interaction.InteractionService.PromptForSelectionAsync[T](String promptText, IEnumerable`1 choices, Func`2 choiceFormatter, CancellationToken cancellationToken) in C:\Code\aspire\src\Aspire.Cli\Interaction\InteractionService.cs:line 69
at Aspire.Cli.Commands.NewCommandPrompter.PromptForTemplatesVersionAsync(IEnumerable`1 candidatePackages, CancellationToken cancellationToken) in C:\Code\aspire\src\Aspire.Cli\Commands\NewCommand.cs:line 227
at Aspire.Cli.Commands.NewCommand.GetProjectTemplatesVersionAsync(ParseResult parseResult, Boolean prerelease, String source, CancellationToken cancellationToken) in C:\Code\aspire\src\Aspire.Cli\Commands\NewCommand.cs:line 130
at Aspire.Cli.Commands.NewCommand.ExecuteAsync(ParseResult parseResult, CancellationToken cancellationToken) in C:\Code\aspire\src\Aspire.Cli\Commands\NewCommand.cs:line 146
at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
Expected Behavior
- The CLI should check if the collection of available templates/packages is empty before attempting to prompt the user.
- If the collection is empty (e.g., due to being offline or misconfigured NuGet sources), the CLI should display a clear, user-friendly error message such as:
"No templates were found. Please check your internet connection or NuGet source configuration."
- The CLI should then exit gracefully without throwing an unhandled exception or displaying a stack trace.
Suggested Solution
- Add an empty-check before calling
PromptForSelectionAsync (and similar methods) in all relevant code paths.
- Display a helpful error message and exit when no choices are available.
- Add tests to cover offline and empty-list scenarios.
Impact
This will result in a better user experience, especially for users working offline or with misconfigured sources, and prevent confusing stack traces.
Problem
When running the
aspire neworaspire addcommands on a machine that is offline (without an internet connection), the CLI currently attempts to prompt the user to select from a list of available template versions or packages. Since no templates/packages are available offline, this results in an unhandled exception and stack trace similar to:Expected Behavior
Suggested Solution
PromptForSelectionAsync(and similar methods) in all relevant code paths.Impact
This will result in a better user experience, especially for users working offline or with misconfigured sources, and prevent confusing stack traces.