Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 25, 2025

Fixes #38172

Summary

This PR enhances dotnet tool restore to show warnings when newer versions of tools are available in the configured package sources. This helps users stay informed about available updates and can prevent issues where outdated tools cause compatibility problems with newer SDKs.

Changes

Core Functionality

  • Enhanced ToolRestoreResult: Added Warning property to carry version update notifications
  • Version Checking Logic: Added CheckForNewerVersion() method in ToolPackageRestorer that:
    • Uses wildcard version ranges (*) to query the latest available version from package sources
    • Compares semantic versions between manifest and latest available
    • Applies smart logic for prerelease vs stable versions
    • Gracefully handles network failures without breaking restore functionality
  • Display Enhancement: Modified PrintConclusionAndReturn() to display warnings in yellow text after successful restore messages

User Experience

  • Localized Messages: Added RestoreNewVersionAvailable resource string with clear, actionable messaging
  • Non-Intrusive: Warnings only appear during dotnet tool restore, never during tool execution
  • Resilient: Network issues or package source problems don't cause restore failures

Example Output

Before:

Tool 'dotnet-ef' (version '6.0.0') was restored. Available commands: dotnet-ef

Restore was successful.

After:

Tool 'dotnet-ef' (version '6.0.0') was restored. Available commands: dotnet-ef

A newer version of tool 'dotnet-ef' is available (version '9.0.9'). Consider updating your manifest file.

Restore was successful.

Testing

  • Added comprehensive unit test coverage for the warning functionality
  • Verified with real-world packages (dotnet-ef, powershell) showing proper version detection
  • Confirmed warnings only appear during restore operations, not tool execution
  • Validated all existing tests pass with no regressions
  • Tested edge cases including latest versions, multiple tools, and network failures

Behavior Notes

  • Scope: Only applies to local tools defined in .config/dotnet-tools.json files
  • Version Logic: Shows warnings for newer stable versions, or any newer version if current is prerelease
  • Performance: Adds minimal overhead during restore by reusing existing package query infrastructure
  • Backward Compatibility: No breaking changes to existing functionality

This addresses the scenario described in the issue where CI systems fail due to outdated tools, but users aren't aware that newer compatible versions are available.

Original prompt

This section details on the original issue you should resolve

<issue_title>dotnet tool restore should provide warnings if new versions of tool is available</issue_title>
<issue_description>### Is your feature request related to a problem? Please describe.
Our CI stopped working as tool needed an old version of SDK (6), which was removed from VM, but tool was on an old version in our .config/dotnet-tools.json... however a new version of the tool was available which worked as-is, but we didn't know at first that this was an option.

Describe the solution you'd like

It'd be great when running dotnet tool restore that if new versions of tools are available, that a warning is outputted to the console which specifies the latest version number.

Even better if there's a way to auto-update the config to use the latest version of all tools in it locally.

Additional context

Add any other context or screenshots about the feature request here.

microsoft/NativeAOTDependencyHelper#16

Related to #38172</issue_description>

<agent_instructions>This should only apply to local tools that are defined in a json file. It should not affect commands outside of restore. For example, if a customer does a tool run, it should use the version in the local tools .json without warning.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #50991

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] dotnet tool restore should provide warnings if new versions of tool is available Add warnings for newer tool versions during dotnet tool restore Sep 25, 2025
@Copilot Copilot AI requested a review from marcpopMSFT September 25, 2025 20:47
Copilot finished work on behalf of marcpopMSFT September 25, 2025 20:47
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.

dotnet tool restore should provide warnings if new versions of tool is available Installing a tool that targets a framework not installed gives a non-actionable error message.
2 participants