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

Download tool packages from NuGet feeds directly, instead of implicitly restoring #33835

Merged
merged 48 commits into from
Sep 19, 2023

Conversation

JL03-Yue
Copy link
Member

@JL03-Yue JL03-Yue commented Jul 6, 2023

PR for issue #31134

Currently, when installing a dotnet tool package, the code restores a temporary project using toolPackageInstaller. This PR updated the methods handling tools to use NuGet API when installing, updating, restoring, and uninstalling global and local tools.

This PR also changes the tests that test the installing, updating, restoring, and uninstalling global and local tools. It also controls the verbosity output from NuGet API when downloading tools.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Tools untriaged Request triage from a team member labels Jul 6, 2023
@JL03-Yue JL03-Yue requested a review from dsplaisted July 6, 2023 21:34
@JL03-Yue JL03-Yue changed the title Download tool packages from nuget when installing global tools Tool install global command: Download tool packages from nuget when installing global tools Jul 7, 2023
@dsplaisted
Copy link
Member

/azp run

@azure-pipelines
Copy link

Pull request contains merge conflicts.

@JL03-Yue JL03-Yue changed the title Tool install global command: Download tool packages from nuget when installing global tools Download tool packages from NuGet feeds directly, instead of implicitly restoring Aug 11, 2023
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.

Great job getting this working!

Some of this is pretty complicated to review, I took a first pass and added my comments, but I will probably have to look at it again later.

Thanks!

@nkolev92
Copy link
Contributor

This implementation must consider PackageSourceMapping. We're moving away from an implementation that considers it, we must not lose that.

I'll review in more detail later.

@dsplaisted
Copy link
Member

This implementation must consider PackageSourceMapping. We're moving away from an implementation that considers it, we must not lose that.

I'll review in more detail later.

@nkolev92 @zivkan We're using NuGet APIs to download a package. The code for that is here. Is there a way to respect package source mapping when calling those APIs?

@nkolev92
Copy link
Contributor

Yeah, I'll link examples later when I review it.

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.

Looking pretty good, great job!

src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
@JL03-Yue JL03-Yue changed the base branch from main to release/8.0.1xx August 30, 2023 20:59
@nkolev92
Copy link
Contributor

NuGet warns for http source since NuGet 6.3 (https://devblogs.microsoft.com/nuget/https-everywhere/) Before this change, dotnet tool install will run implicit restore so NuGet is able to warn customer about http source when installing dotnet tool. However, after this change, there will be no warning for http source when installing dotnet tool. Hi @JonDouglas @aortiz-msft @nkolev92 @zivkan do you have any concerns about this?

That's a great catch! I think that should be added as well.

@JonDouglas
Copy link

We want to have a consistent experience everywhere we can. Since most of that is implemented at restore, could we somehow provide a central API or similar piping for NuGet APIs as well? That way it is rather easy for people to contribute these types of changes without having to know about all the NuGet best security practices and years of work going into restore security?

@nkolev92
Copy link
Contributor

We want to have a consistent experience everywhere we can. Since most of that is implemented at restore, could we somehow provide a central API or similar piping for NuGet APIs as well? That way it is rather easy for people to contribute these types of changes without having to know about all the NuGet best security practices and years of work going into restore security?

http warnings, PSM, signature verification are concerns at different parts of restore, so they're not really implemented at the same level.

Adding a central API end up being something that's not used anywhere within the NuGet code itself, so we wouldn't know how to best author it.
After some discussions (maybe @zivkan was a part of that?), downloading was implemented on the SDK side (plus time constraints).

@zivkan mentioned this in a side-chat, but I think this is showing that we need to add some tests testing NuGet scenarios within in this repo, regardless of how stuff gets implemented :)

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.

I still want to take a look at the tests, but I think I've reviewed everything else in detail now.

Let's take a look at the feedback together.

src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
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.

I've finished reviewing the tests now too. Some of the feedback here we've already discussed live.

I also think we should add tests for some scenarios where the package has already been downloaded or the tool has already been installed in another local tools folder.

src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
packageSourceMapping: mockPackageSourceMapping).GetAwaiter().GetResult();
a.Should().Throw<NuGetPackageInstallerException>().And.Message.Should().Contain(string.Format(Cli.NuGetPackageDownloader.LocalizableStrings.FailedToGetPackageUnderPackageSourceMapping, TestPackageId));
}

Copy link
Member

Choose a reason for hiding this comment

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

I think we should have a test where package source mapping is configured correctly, and verify that it can download successfully. I'm not sure yet what the best way to write such a test would be.

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.

Great job! We're almost there, just a few remaining comments.

src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
Comment on lines +112 to +113
NuGetv3LocalRepository localRepository = new(toolDownloadDir.Value);
var package = localRepository.FindPackage(packageId.ToString(), packageVersion);
Copy link
Member

Choose a reason for hiding this comment

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

This only applies to local tools. So I tihnk it should probably be in a block that only applies to local tools (such as an else statement from the previous suggestion).

src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Tools untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.