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

dotnet package list command should restore first #47873

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

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

@dotnet-issue-labeler dotnet-issue-labeler bot 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
@Nigusu-Allehu Nigusu-Allehu force-pushed the dev-nyenework-dlp-implicit-restore branch from 5ff051a to a8235d6 Compare March 26, 2025 15:04

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.


if (formatOption == ReportOutputFormat.json)
{
args = ["-target:restore", projectOrSolution, "-noConsoleLogger"];
Copy link
Member

Choose a reason for hiding this comment

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

tiny nit: -target:Restore

{
string jsonError = $$"""
{
"version": 1,
Copy link
Member

Choose a reason for hiding this comment

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

What version is this?

string jsonError = $$"""
{
"version": 1,
"problems": [
Copy link
Member

Choose a reason for hiding this comment

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

"errors"? Or since this doesn't really seem to be an array, can we just make it "error" and have it be the object?

]
}
""";
Console.WriteLine(jsonError);
Copy link
Member

Choose a reason for hiding this comment

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

This feels like it should go elsewhere. Does NuGet normally just write to the console? Seems like there should be some kind of logger, or at least this should go to Console.Error

@@ -174,4 +174,11 @@
<data name="CmdOutputVersionDescription" xml:space="preserve">
<value>Specifies the version of machine-readable output. Requires the '--format json' option.</value>
</data>
<data name="Error_restore" xml:space="preserve">
<value>Restore failed. Run `dotnet restore` for more details on the issue.</value>
<comment>Do not translate `dotnet restore`</comment>
Copy link
Member

Choose a reason for hiding this comment

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

nit: use the locking syntax for pinned translation strings so that the Loc team's tooling helps prevent unintentional translation.

}

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

Choose a reason for hiding this comment

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

I was looking this and comparing it with RestoringCommand. I'm not entirely sure why they look so different. This looks correct, as far as I can tell; I just thought it'd would be nice to combine them if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure 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
5 participants