-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add tests for package@version and --version conflict validation in tool install/update #52707
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: baronfel <[email protected]>
Co-authored-by: baronfel <[email protected]>
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds explicit regression tests ensuring dotnet tool install / dotnet tool update reject using both package@version and --version together (validating the existing conflict check surfaced via GracefulException).
Changes:
- Added a new test covering
dotnet tool install -g package@version --version ...conflict behavior. - Added a new test covering
dotnet tool update -g package@version --version ...conflict behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/dotnet.Tests/CommandTests/Tool/Install/InstallToolParserTests.cs | Adds a test asserting the @version + --version conflict throws the expected localized error. |
| test/dotnet.Tests/CommandTests/Tool/Update/UpdateToolParserTests.cs | Adds a parallel test for tool update validating the same conflict behavior. |
| var toolInstallCommand = new Cli.Commands.Tool.Install.ToolInstallCommand(result); | ||
|
|
||
| Action a = () => toolInstallCommand.Execute(); | ||
|
|
||
| a.Should().Throw<GracefulException>().And.Message | ||
| .Should().Contain(Cli.CliStrings.PackageIdentityArgumentVersionOptionConflict); |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cli.Commands... and Cli.CliStrings... won’t compile here because Cli isn’t in scope (there’s no using Microsoft.DotNet;/alias). Since you already import Microsoft.DotNet.Cli.Commands.Tool.Install, instantiate ToolInstallCommand directly, and reference the resource string as CliStrings.PackageIdentityArgumentVersionOptionConflict (add using Microsoft.DotNet.Cli; or fully-qualify Microsoft.DotNet.Cli.CliStrings).
| var toolUpdateCommand = new Cli.Commands.Tool.Update.ToolUpdateCommand(result); | ||
|
|
||
| Action a = () => toolUpdateCommand.Execute(); | ||
|
|
||
| a.Should().Throw<GracefulException>().And.Message | ||
| .Should().Contain(Cli.CliStrings.PackageIdentityArgumentVersionOptionConflict); |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cli.Commands... and Cli.CliStrings... won’t compile here because Cli isn’t in scope (there’s no using Microsoft.DotNet;/alias). Since you already import Microsoft.DotNet.Cli.Commands.Tool.Update, instantiate ToolUpdateCommand directly, and reference the resource string as CliStrings.PackageIdentityArgumentVersionOptionConflict (add using Microsoft.DotNet.Cli; or fully-qualify Microsoft.DotNet.Cli.CliStrings).
The
package@versionsyntax fordotnet tool installanddotnet tool updateis already implemented viaCommonArguments.ParsePackageIdentityWithVersionSeparator. The conflict validation (using both@versionand--version) is also implemented inVersionRangeUtilities.GetVersionRange. However, there were no explicit tests for this validation.Changes
InstallToolWithBothAtVersionAndVersionOptionThrowsErrortest inInstallToolParserTests.csUpdateToolWithBothAtVersionAndVersionOptionThrowsErrortest inUpdateToolParserTests.csExample
CLI Commands with Package IDs and
--versionoptionspackage@versiondotnet package adddotnet tool installdotnet tool updatedotnet tool executeOther commands like
workload install/updateuse--sdk-version(not package versions), andpackage removehas no version option.Original prompt
dotnet tool installdoesn't supportpackage@versionsyntax #52706💡 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.