NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 250 forks source link

`dotnet add package` is too verbose #12548

Open richlander opened 1 year ago

richlander commented 1 year ago

NuGet Product(s) Affected

dotnet.exe

Current Behavior

This is the default experience for dotnet add package.

% dotnet add package spectre.console
  Determining projects to restore...
  Writing /var/folders/g5/4rfd120s6bg5b3nj03bryglr0000gn/T/tmpQAjnQA.tmp
info : X.509 certificate chain validation will use the fallback certificate bundle at '/usr/local/share/dotnet/sdk/8.0.100-preview.3.23178.7/trustedroots/codesignctl.pem'.
info : X.509 certificate chain validation will use the fallback certificate bundle at '/usr/local/share/dotnet/sdk/8.0.100-preview.3.23178.7/trustedroots/timestampctl.pem'.
info : Adding PackageReference for package 'spectre.console' into project '/Users/rich/git/font/LedMatrix/samples/Matrix.samples.csproj'.
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/index.json
info :   OK https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/index.json 82ms
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.0.1/0.19.0.json
info :   OK https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.0.1/0.19.0.json 82ms
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.19.1-preview.0.1/0.32.1.json
info :   OK https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.19.1-preview.0.1/0.32.1.json 81ms
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.32.2-preview.0.1/0.37.1-preview.0.38.json
info :   OK https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.32.2-preview.0.1/0.37.1-preview.0.38.json 84ms
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.37.1-preview.0.39/0.40.1-preview.0.8.json
info :   OK https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.37.1-preview.0.39/0.40.1-preview.0.8.json 83ms
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.40.1-preview.0.9/0.43.1-preview.0.41.json
info :   OK https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.40.1-preview.0.9/0.43.1-preview.0.41.json 87ms
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.43.1-preview.0.42/0.45.1-preview.0.49.json
info :   OK https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.43.1-preview.0.42/0.45.1-preview.0.49.json 85ms
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.45.1-preview.0.51/0.46.1-preview.0.20.json
info :   OK https://api.nuget.org/v3/registration5-gz-semver2/spectre.console/page/0.45.1-preview.0.51/0.46.1-preview.0.20.json 80ms
info : Restoring packages for /Users/rich/git/font/LedMatrix/samples/Matrix.samples.csproj...
info :   GET https://api.nuget.org/v3-flatcontainer/spectre.console/index.json
info :   OK https://api.nuget.org/v3-flatcontainer/spectre.console/index.json 84ms
info :   GET https://api.nuget.org/v3-flatcontainer/spectre.console/0.46.0/spectre.console.0.46.0.nupkg
info :   OK https://api.nuget.org/v3-flatcontainer/spectre.console/0.46.0/spectre.console.0.46.0.nupkg 120ms
info : Installed Spectre.Console 0.46.0 from https://api.nuget.org/v3/index.json with content hash qd2OMEGxfQW1KLuQj56KKHkIK6eB/IUF/AET5CRl/efROHGsvBehx9shfkL0HgJEHLCwRiR7foWi4/LkdPk18g==.
info : Package 'spectre.console' is compatible with all the specified frameworks in project '/Users/rich/git/font/LedMatrix/samples/Matrix.samples.csproj'.
info : PackageReference for package 'spectre.console' version '0.46.0' added to file '/Users/rich/git/font/LedMatrix/samples/Matrix.samples.csproj'.
info : Writing assets file to disk. Path: /Users/rich/git/font/LedMatrix/samples/obj/project.assets.json
log  : Restored /Users/rich/git/font/LedMatrix/samples/Matrix.samples.csproj (in 1.78 sec).

This looks like excellent output for "verbose mode". I am wondering why this is the default experience since there is no call to action from this information in the success case. We should aim to simplify UX. This flow is presumably popular enough that we should seek to improve it.

I don't believe that there is another experience in the product that has this same level of console output.

Here is a nice counterexample, doing something very similar.

% dotnet tool install -g dotnet-runtimeinfo  
Skipping NuGet package signature verification.
You can invoke the tool using the following command: dotnet-runtimeinfo
Tool 'dotnet-runtimeinfo' (version '1.0.5') was successfully installed.

Also, there isn't an obvious way to control verbosity.

% dotnet add package --help         
Description:
  Add a NuGet package reference to the project.

Usage:
  dotnet add [<PROJECT>] package <PACKAGE_NAME> [options]

Arguments:
  <PROJECT>       The project file to operate on. If a file is not specified, 
                  the command will search the current directory for one. 
                  [default: /Users/rich/git/font/LedMatrix/samples/]
  <PACKAGE_NAME>  The package reference to add.

Options:
  -v, --version <VERSION>            The version of the package to add.
  -f, --framework <FRAMEWORK>        Add the reference only when targeting a 
                                     specific framework.
  -n, --no-restore                   Add the reference without performing 
                                     restore preview and compatibility check.
  -s, --source <SOURCE>              The NuGet package source to use during the 
                                     restore.
  --package-directory <PACKAGE_DIR>  The directory to restore packages to.
  --interactive                      Allows the command to stop and wait for 
                                     user input or action (for example to 
                                     complete authentication).
  --prerelease                       Allows prerelease packages to be installed.
  -?, -h, --help                     Show command line help.

Desired Behavior

Provide output that is useful for the scenario.

Additional Context

https://github.com/dotnet/sdk/issues/31946

JonDouglas commented 1 year ago

Looks like a codepath hitting info or normal verbosity for the implicit restore.

We should respect verbosity throughout the NuGet commands and then work on saying just enough for each level.

Priority wise this is a nice to have, perhaps we can define some SDK best practices for CLI verbosity output given the only thing I've found is to ensure verbosity is respected.

https://clig.dev/

https://github.com/dotnet/sdk/blob/main/documentation/general/cli-ux-guidelines.md#verbosity

richlander commented 1 year ago

@baronfel

baronfel commented 1 year ago

We've captured additional dotnet CLI guidelines in a section of suggestions for CLI authors using System.CommandLine here.

Generally 3 levels seem to be enough:

For this specific case, I can see a few lines that I think would qualify for 'normal' output:

info: Adding PackageReference for package 'spectre.console' into project '/Users/rich/git/font/LedMatrix/samples/Matrix.samples.csproj'. info: Package 'spectre.console' is compatible with all the specified frameworks in project '/Users/rich/git/font/LedMatrix/samples/Matrix.samples.csproj'. info: PackageReference for package 'spectre.console' version '0.46.0' added to file '/Users/rich/git/font/LedMatrix/samples/Matrix.samples.csproj'.

Basically everything talking about implicit restore should be behind the diagnostic verbosity level IMO, and the verbosity level should not leak as a 'prefix' in otherwise-unstructured messages.

We do have other knobs here, though - if a quiet mode was implemented on the NuGet side, the final output/layout/etc could be handled entirely in the dotnet CLI if the team didn't want to impact NuGet's output directly.

heng-liu commented 1 year ago

This seems a duplicate issue of #6374 dotnet-nuget doesn't support verbosity. From the code, we can see that only the later commands dotnet nuget verify/sign command implement the verbosity in NuGet.CommandLine.XPlat.

johnbrimley commented 1 year ago

If this ticket is still available for community contrib I'd be interested in a taking a look at it.

JonDouglas commented 1 year ago

@johnbrimley please feel free! We marked it help wanted. If you need help, we can assist through PR review.