Skip to content

dotnet package list command should restore first #47873

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

Merged
merged 13 commits into from
Apr 9, 2025

Conversation

Nigusu-Allehu
Copy link
Member

@Nigusu-Allehu Nigusu-Allehu commented Mar 25, 2025

#47400 had to many conflicts.
Fixes: NuGet/Home#13406

Description

This PR

ScreenShots

  • package list --project [project]
    image

  • --format json
    image

  • restore error
    image

  • restore error: --format json
    image

@ghost ghost added Area-Infrastructure untriaged Request triage from a team member labels Mar 25, 2025
@Nigusu-Allehu Nigusu-Allehu self-assigned this Mar 25, 2025
@Nigusu-Allehu Nigusu-Allehu marked this pull request as ready for review March 25, 2025 17:08
@Nigusu-Allehu Nigusu-Allehu requested a review from a team as a code owner March 25, 2025 17:08

private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption)
{
MSBuildForwardingApp restoringCommand = new MSBuildForwardingApp(argsToForward: ["-target:restore", projectOrSolution, "-noConsoleLogger"]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the implicit restore isn't logging anything, what if its takes more than a few seconds? I think the user might think something is wrong. We could pass console logger parameters to produce some output

-consoleLoggerParameters:Verbosity=Minimal;NoSummary

Copy link
Member

Choose a reason for hiding this comment

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

We should try to align with test and run here and use the same logger configuration - ideally this would use terminal logger by default like every other command in the CLI.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not so sure, the output of this command is the information about the packages that a project is referencing. Its not running tests (which are potentially long running) and its not building a project and its dependencies.

The only reason we need to run restore first is because the project.assets.json file provides all of the information and we want to make sure its up-to-date. The only reason I propose we have any output at all about restore is in the case that it takes a while, I don't want users to think that dotnet list package is hung.

@Nigusu-Allehu Nigusu-Allehu requested a review from jeffkl March 28, 2025 20:08
@Nigusu-Allehu Nigusu-Allehu requested review from zivkan and Forgind March 28, 2025 23:06
@Nigusu-Allehu
Copy link
Member Author

Nigusu-Allehu commented Apr 7, 2025

review request: @dotnet/nuget-team any suggestions/comments? The more time this takes the more conflicts keep coming up

: restoreExitCode;
}

private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption, bool interactive)
Copy link

Choose a reason for hiding this comment

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

Nit: This method does a lot of things to prepare the command to run. Consider adding private helper methods to set up the options and generate the json output and call them from this method.

<data name="Error_restore" xml:space="preserve">
<value>Restore failed. Run `dotnet restore` for more details on the issue.</value>
Copy link

Choose a reason for hiding this comment

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

Question: Is this wording consistent with other output or was this wording vetted?

Copy link
Contributor

Choose a reason for hiding this comment

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

On that note, why can't we output the error from dotnet restore without them having to run dotnet restore explicitly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Question: Is this wording consistent with other output or was this wording vetted?

This the first adoption of implicit restore for nuget commands. Others like dotnet nuget why will probably follow suit as well.

On that note, why can't we output the error from dotnet restore without them having to run dotnet restore explicitly?

When the command includes --format json, we avoid printing any additional output to ensure the JSON remains valid. To enforce this, I passed -noConsoleLogger to MSBuild. Since this operation runs in a separate process, capturing and displaying errors becomes tricky. If we were running the restore in-process, however, we could have easily captured the errors and logged them ourselves.

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think this is a perfectly valid response, but I'll bang this drum on baronfel's behalf:
Output should go to stdout. Errors (and other incidental output) should go to stderr. That way you can have beautiful, clean output in stdout and still have access to all the information you'd want in stderr.

I'm assuming NuGet doesn't do that historically, so you're sending errors to stdout as well just because that's how it currently works?

Though if you're going to get an error anyway, does the user really still care that the output of --format json is preserved?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is good point! Tracking here now NuGet/Home#14239

@marcpopMSFT
Copy link
Member

@Nigusu-Allehu there are a bunch of conflicts to resolve fyi.

@Nigusu-Allehu Nigusu-Allehu force-pushed the dev-nyenework-dlp-implicit-restore branch from a443cdd to c5f737f Compare April 8, 2025 21:37
@Nigusu-Allehu Nigusu-Allehu merged commit 5a637f3 into main Apr 9, 2025
39 checks passed
@Nigusu-Allehu Nigusu-Allehu deleted the dev-nyenework-dlp-implicit-restore branch April 9, 2025 15:15
@aortiz-msft aortiz-msft added the breaking-change Using this label will notify dotnet/compat and trigger a request to file a compat bug label Apr 15, 2025
Copy link
Contributor

dotnet-policy-service bot commented Apr 15, 2025

@Nigusu-Allehu: Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET SDK Breaking Change Notification email list.

You can refer to the .NET SDK breaking change guidelines

@Nigusu-Allehu
Copy link
Member Author

breaking change doc: dotnet/docs#46103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure breaking-change Using this label will notify dotnet/compat and trigger a request to file a compat bug untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dotnet list package doesn't restore
8 participants