Skip to content

Add warnings for newer tool versions during dotnet tool restore#51011

Merged
marcpopMSFT merged 4 commits intomainfrom
copilot/fix-43788e6e-9f45-41c4-a7b1-05113aa76e24
Dec 17, 2025
Merged

Add warnings for newer tool versions during dotnet tool restore#51011
marcpopMSFT merged 4 commits intomainfrom
copilot/fix-43788e6e-9f45-41c4-a7b1-05113aa76e24

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 25, 2025

  • Explored repository structure and understood the codebase
  • Located the ToolRestoreCommand and related files
  • Identified the current restoration flow in ToolPackageRestorer.InstallPackage()
  • Found CLI string resources for messaging
  • Identified existing test infrastructure
  • Added new CLI string for warning about newer versions
  • Extended ToolRestoreResult to include warning information
  • Modified ToolPackageRestorer to check for newer versions after successful restore
  • Updated PrintConclusionAndReturn to display warnings in yellow text
  • Added comprehensive test for warning functionality
  • Verified build succeeds and test passes
  • Manual testing with real packages (dotnet-ef, powershell)
  • Verified warnings only appear during restore, not tool execution
  • Confirmed all existing tests pass with no regressions
  • Tested edge cases (latest version, multiple tools, network issues)
  • Addressed PR feedback: Fixed formatting indentation
  • Added tests for prerelease version behaviors

Changes in this commit:

  • Fixed indentation of warning: parameter in ToolPackageRestorer.cs (line 103)
  • Improved existing test to use explicit versions to prevent breaking when _packageVersionA changes
  • Added test for prerelease-to-stable upgrade warning
  • Added test for stable-to-prerelease (no warning) behavior

Test Coverage:

  • Basic version upgrade warning
  • Prerelease to stable version warning
  • Stable to prerelease (no warning - prevents prerelease noise)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
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 AI requested a review from marcpopMSFT September 25, 2025 20:47
@marcpopMSFT
Copy link
Copy Markdown
Member

@baronfel I tested and this new code only runs if the current version of the tool is not found in the cache. That seems like an ok compromise to me as otherwise, we're hitting the network when theoretically we don't need to. However, it does mean that if you have the tool installed locally, you'll never get the notice.

@marcpopMSFT
Copy link
Copy Markdown
Member

Tool 'dotnetsay' (version '2.1.1') was restored. Available commands: dotnetsay

A newer version of tool 'dotnetsay' is available (version '2.1.7'). Consider updating your manifest file.

@baronfel
Copy link
Copy Markdown
Member

baronfel commented Oct 3, 2025

That's an interesting compromise for sure. I could see a dotnet tool check command in the future for more comprehensive checking.

@marcpopMSFT marcpopMSFT requested a review from baronfel October 7, 2025 23:13
@marcpopMSFT marcpopMSFT marked this pull request as ready for review October 7, 2025 23:13
Copilot AI review requested due to automatic review settings October 7, 2025 23:13
@marcpopMSFT
Copy link
Copy Markdown
Member

or a flag to dotnet tool restore which asks for the check. Either way, this change is reasonable and working as is so published for review.

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

This PR adds functionality to display warnings when newer versions of tools are available during dotnet tool restore operations. This helps users stay informed about tool updates and prevent compatibility issues with newer SDKs.

Key Changes:

  • Enhanced restore functionality to check for newer tool versions and display warnings
  • Added localized warning messages for the new version notification feature
  • Implemented comprehensive test coverage for the warning functionality

Reviewed Changes

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

Show a summary per file
File Description
ToolPackageRestorer.cs Added version checking logic and warning generation functionality
ToolRestoreCommand.cs Enhanced result structure and display logic to show version warnings
CliCommandStrings.resx Added the new localized message string for version warnings
Multiple .xlf files Added localization entries for the new warning message
ToolRestoreCommandTests.cs Added comprehensive test coverage for the warning functionality

Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf
@KalleOlaviNiemitalo
Copy link
Copy Markdown
Contributor

This PR enhances dotnet tool restore to show warnings when newer versions of tools are available in the configured package sources.

I saw this and immediately worried about such a warning getting triggered in an automated build, being parsed by Jenkins and causing the build to be considered UNSTABLE.

It looks like the output is not actually formatted anything like "warning SDK0000: tool is not the latest available version" though, so it won't be parsed as a warning. Please call it a note, then.

@marcpopMSFT
Copy link
Copy Markdown
Member

@KalleOlaviNiemitalo yeah, this in the bucket of CLI messages so shouldn't impact exit codes or builds. It can impact if someone is processing the output.

@marcpopMSFT marcpopMSFT requested a review from nagilson November 4, 2025 21:19
Comment thread src/Cli/dotnet/Commands/Tool/Restore/ToolPackageRestorer.cs
// Use wildcard version range to get the latest version
var latestVersionRange = VersionRange.Parse("*");

var (latestVersion, _) = _toolPackageDownloader.GetNuGetVersion(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm pretty confident this won't add additional unexpected terminal output, so that's good.

if (latestVersion != null && latestVersion > package.Version)
{
// If the current version is prerelease, show warning for any newer version
// If the current version is stable, only show warning for newer stable versions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice comments here 👍



// Display warnings for successful restorations even in partial failure case
var warnings = toolRestoreResults.Where(r => r.IsSuccess && !string.IsNullOrEmpty(r.Warning)).Select(r => r.Warning);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting, so we're returning it as a regular, (but yellow) line instead of a warning to prevent breaking changes. Seems good.

[Fact]
public void WhenNewerVersionIsAvailableItShowsWarning()
{
var newerPackageVersion = NuGetVersion.Parse("2.1.4");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: we could probably add to the _packageVersionA to prevent updating that from breaking this test.

@copilot We also don't test the prerelease version behaviors, which seems significant enough that we should test to prevent regression.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in commit 1f3148a. The test now uses explicit versions to avoid breaking if _packageVersionA changes. Also added two tests for prerelease behaviors:

  • Prerelease to stable: Shows warning
  • Stable to prerelease: Does NOT show warning (prevents prerelease noise)

Copy link
Copy Markdown
Member

@nagilson nagilson left a comment

Choose a reason for hiding this comment

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

Looks good - let's validate it adds the test and if it doesn't change anything else we should be good to go

Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Copy link
Copy Markdown
Member

@nagilson nagilson left a comment

Choose a reason for hiding this comment

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

Nicely done on the new test.

@marcpopMSFT marcpopMSFT merged commit 2e8fc8b into main Dec 17, 2025
29 checks passed
@marcpopMSFT marcpopMSFT deleted the copilot/fix-43788e6e-9f45-41c4-a7b1-05113aa76e24 branch December 17, 2025 23:04
@marcpopMSFT
Copy link
Copy Markdown
Member

/backport to release/10.0.3xx

@github-actions
Copy link
Copy Markdown
Contributor

Started backporting to release/10.0.3xx (link to workflow run)

@github-actions
Copy link
Copy Markdown
Contributor

@marcpopMSFT backporting to release/10.0.3xx failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Patch format detection failed.
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@github-actions
Copy link
Copy Markdown
Contributor

Started backporting to release/10.0.3xx (link to workflow run)

@github-actions
Copy link
Copy Markdown
Contributor

@marcpopMSFT backporting to release/10.0.3xx failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Patch format detection failed.
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@baronfel
Copy link
Copy Markdown
Member

baronfel commented Jan 28, 2026

manual backport pr for 10.0.3xx is #52715

@KalleOlaviNiemitalo
Copy link
Copy Markdown
Contributor

Does this show a warning if:

  • the manifest specifies version 1.0.0
  • the feed has versions 1.0.0, 1.1.0, and 1.2.0-rc.1

In this case, I think it should warn that the newer stable version 1.1.0 is available; but the implementation looks like it won't warn anything about versions, because the latest version 1.2.0-rc.1 is a prerelease but the specified version 1.0.0 is stable.

@marcpopMSFT
Copy link
Copy Markdown
Member

@KalleOlaviNiemitalo see the code here: https://github.com/dotnet/sdk/blob/main/src/Cli/dotnet/Commands/Tool/Restore/ToolPackageRestorer.cs#L159

If the current version is a prerelease, it'll tell you if there's a newer prerelease. Otherwise, it won't tell you to update to a prerelease. Looking at the code, there is a slight gap in the scenario you mentioned where if there is a prerelease, we won't tell you about the latest stable version to upgrade to. Not sure how common that is but if you think it's worth improving the logic for, feel free to file an issue and we'll see if copilot can change the GetNuGetVersion call to account for that. Not something I'd prioritize as that seems more niche.

@KalleOlaviNiemitalo
Copy link
Copy Markdown
Contributor

Linking back to #50991 for reference. This link was originally in the PR description but Copilot edited it out on December 10.

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.

6 participants