Skip to content

Add CLI version update notifications to Aspire CLI #9992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 23, 2025

Summary

Implements automatic update notifications for the Aspire CLI that notify users when newer versions are available on NuGet, following the specified notification rules for stable and prerelease versions.

Changes

Core Implementation

  • Extended INuGetPackageCache with GetCliPackagesAsync() method to query Aspire.Cli packages with 1-hour cache expiration
  • Enhanced NuGetPackagePrefetcher to prefetch CLI versions in background alongside existing template prefetch
  • Created CliUpdateNotificationService that implements version comparison logic and displays update notifications
  • Integrated into Program.Main to check for updates after successful command execution

Notification Rules

The implementation follows the exact rules specified in the issue:

  1. Prerelease → Stable: If using a prerelease version lower than the latest stable version, prompt to upgrade to stable
  2. Prerelease → Prerelease: If using a prerelease version and a newer prerelease is available, prompt to upgrade
  3. Stable → Stable: If using a stable version and a newer stable version is available, prompt to upgrade

Example Output

A new version of the Aspire CLI is available: 9.0.0
Update using: dotnet tool update --global Aspire.Cli
For more information, see: https://aka.ms/aspire/update-cli

Key Features

  • Background Processing: Version checks happen during CLI startup for better performance
  • Smart Caching: 1-hour cache expiration for CLI updates vs longer cache for templates
  • Graceful Error Handling: Update check failures don't impact main CLI functionality
  • Help Command Skip: Prevents notification spam on help/version commands
  • Semantic Versioning: Uses existing SemVersion.PrecedenceComparer for proper version comparison

Files Changed

  • src/Aspire.Cli/NuGet/NuGetPackageCache.cs - Added CLI package query method
  • src/Aspire.Cli/NuGet/NuGetPackagePrefetcher.cs - Extended to prefetch CLI versions
  • src/Aspire.Cli/Utils/CliUpdateNotificationService.cs - New service for update logic
  • src/Aspire.Cli/Program.cs - Integration into main CLI flow
  • tests/Aspire.Cli.Tests/Utils/CliUpdateNotificationServiceTests.cs - Unit tests

Testing

Added unit tests that verify:

  • Service handles newer versions correctly
  • Service handles empty package lists gracefully
  • Version comparison logic follows the specified rules
  • Integration with existing test infrastructure

Implementation Notes

  • Reuses existing NuGet infrastructure (prefetcher, cache, CLI runner) as suggested in the issue
  • Follows repository patterns for dependency injection, error handling, and background services
  • Minimal changes - extends existing functionality rather than replacing it
  • No breaking changes to existing CLI behavior

The feature is now ready for users to receive automatic notifications about available CLI updates during normal usage.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits June 23, 2025 15:04
Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Aspire CLI: Upgrade Notification for New Versions (NuGet Prefetch + End-of-Command Notice) Add CLI version update notifications to Aspire CLI Jun 23, 2025
@Copilot Copilot AI requested a review from mitchdenny June 23, 2025 15:14
Copilot finished work on behalf of mitchdenny June 23, 2025 15:14
{
try
{
await nuGetPackageCache.GetCliPackagesAsync(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot consolidate this code into the background task above, there is no need to fire off two tasks here. They can both be done concurrently and a Task.WhenAny can be used to merge them back in. Move each prefetch operation into its own method so that a log message can be customized for each one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've consolidated the code as requested. The two separate Task.Run operations are now combined into a single background task using Task.WhenAll, and I've extracted PrefetchTemplatePackagesAsync() and PrefetchCliPackagesAsync() methods with customized log messages for each operation. The CLI packages prefetch method now includes "for update notifications" in its log message to distinguish it from the template prefetch. Commit: 7a25bf8

Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
@Copilot Copilot AI requested a review from mitchdenny June 23, 2025 15:30
Copilot finished work on behalf of mitchdenny June 23, 2025 15:30
@davidfowl
Copy link
Member

Is this going to show up when you don't acquire it as a .NET tool?

@@ -174,11 +175,30 @@ public static async Task<int> Main(string[] args)
using var activity = telemetry.ActivitySource.StartActivity();
var exitCode = await config.InvokeAsync(args);

// Check for CLI updates after command execution
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why after?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the update check to run before command execution instead of after. This provides better user experience by showing notifications upfront rather than after the user's intended operation completes. The check still skips help commands to avoid notification spam. Commit: aa134f2

…tool and move to before command execution

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 24, 2025

Is this going to show up when you don't acquire it as a .NET tool?

I've added detection logic to only show update notifications when the CLI is running as a .NET global tool. The service now checks if the process path or base directory contains ".dotnet/tools" (the typical location for global tools) and skips the notification if it's not detected. This prevents misleading update instructions for users running the CLI from source builds or other non-tool installations. Commit: aa134f2

Copilot finished work on behalf of davidfowl June 24, 2025 06:01
@Copilot Copilot AI requested a review from davidfowl June 24, 2025 06:01
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.

3 participants