Skip to content
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

Add automatically tool upgrade and downgrade for different versions for dotnet tool install #37311

Merged
merged 24 commits into from
Jan 9, 2024

Conversation

JL03-Yue
Copy link
Member

@JL03-Yue JL03-Yue commented Dec 4, 2023

#9500

Update dotnet tool install for global or local tools so that it support automatic upgrade, downgrade, and error-throwing behaviors.

behaviors

  • If the command doesn't specify version, the latest version is installed. Exit code = 0
  • If the command specify version 3.0.0 and version 3.0.0 is installed, do nothing. Exit code = 0
  • If the command specify version 3.0.0 and version 2.0.0 is installed, upgrade to 3.0.0. Exit code = 0
  • If the command specify version 3.0.0 without --allow-downgrade flag and version 4.0.0 is installed, it throws out an error.
  • If the command specify version 3.0.0 with--allow-downgrade flag and version 4.0.0 is installed, downgrade to 3.0.0. Exit code = 0

User cases

  • Tool install
$ dotnet__ tool install (-g) Cake.tool --version 3.0.0 --verbosity minimal
You can invoke the tool using the following command: dotnet-cake
Tool 'cake.tool' (version '3.0.0') was successfully installed.
$ dotnet tool install (-g) Cake.tool --version 3.0.0 --verbosity minimal
Tool 'cake.tool' was reinstalled with the stable version (version '3.0.0').
$ dotnet tool install (-g) Cake.tool --verbosity minimal
Tool 'cake.tool' was successfully updated from version '3.0.0' to version '4.0.0'.
$ dotnet tool install (-g) Cake.tool --version 2.0.0 --verbosity minimal
The requested version 2.0.0 is lower than existing version 4.0.0.
$ dotnet tool install (-g) Cake.tool --version 2.0.0 --allow-downgrade --verbosity minimal
Tool 'cake.tool' was successfully updated from version '4.0.0' to version '2.0.0'.
  • Tool update
$ dotnet tool install (-g) Cake.tool --version 3.0.0 --verbosity minimal
You can invoke the tool using the following command: dotnet-cake
Tool 'cake.tool' (version '3.0.0') was successfully installed.
$ dotnet tool update (-g) Cake.tool --verbosity minimal
Tool 'cake.tool' was successfully updated from version '3.0.0' to version '4.0.0'.
$ dotnet tool update (-g) Cake.tool --version 4.0.0 --verbosity minimal
Tool 'cake.tool' was reinstalled with the stable version (version '4.0.0').
$ dotnet tool update (-g) Cake.tool --version 2.0.0 --verbosity minimal
The requested version 2.0.0 is lower than existing version 4.0.0.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Infrastructure untriaged Request triage from a team member labels Dec 4, 2023
@JL03-Yue
Copy link
Member Author

JL03-Yue commented Dec 9, 2023

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@dsplaisted dsplaisted left a comment

Choose a reason for hiding this comment

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

Looks great!

We should probably have test cases for each of the different behaviors in the PR description, for global and local tools. Probably some of those cases are already covered.

@JL03-Yue JL03-Yue merged commit 75b02ea into dotnet:release/8.0.2xx Jan 9, 2024
16 checks passed
@JL03-Yue JL03-Yue added Area-Tools and removed untriaged Request triage from a team member Area-Infrastructure labels Apr 12, 2024
Forgind pushed a commit that referenced this pull request Jun 27, 2024
Fixes #40818

Context

Following the changes introduced in #37311, the dotnet tool install --global command began reinstalling tools that were already installed, which involved deleting and then adding the same tool version again. Before this release, it was not possible to install a version that was already installed.

This behavior change was reported in #40818. I propose a modification to avoid reinstalling tools that are already installed.

Change

The current installation flow involves uninstalling all matching tools and then installing them again. My change modifies this flow by first checking if the requested best match package version is already installed. If it is, the flow is stopped, and a message is printed: 'Tool '{0}' is already installed'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants