dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.72k stars 1.07k forks source link

Deduplicate NuGet sources provided from NuGet.Config and .NET CLI arguments for tool install #43507

Open baronfel opened 1 month ago

baronfel commented 1 month ago

Is your feature request related to a problem? Please describe.

When a user has a NuGet.config with a source in it and also provides that same source URL from the commandline via the --add-source CLI option, our usage of the NuGet APIs treats that as 2 distinct sources. If that source requires authentication, then that authentication only applies to one of the sources (often the one from the NuGet.config). This leads to hard-to-diagnose failures when the duplicate source is used for the tool installation.

Describe the solution you'd like

Tool install (and possibly any other command that supports the --add-source semantic) should deduplicate the sources used for the install based on the URL.

dsplaisted commented 1 month ago

@nkolev92 @zivkan Any thoughts on this? A feed might be configured differently in NuGet.config than it would be with --add-source, so I'm not sure what the correct de-duping behavior would be.

nkolev92 commented 1 month ago

Dedup and take the credentials from the config. Basically dedup and take the PackageSource created by the config APIs.

Some related code: https://github.com/NuGet/NuGet.Client/blob/e082545cbba30ec8dc9b759f2d9beea8aabc6215/src/NuGet.Core/NuGet.Commands/RestoreCommand/RequestFactory/RestoreArgs.cs#L169-L176

Some logic you might be able to follow in https://github.com/NuGet/NuGet.Client/blob/e082545cbba30ec8dc9b759f2d9beea8aabc6215/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommand.cs#L245-L265

which effecitvely calls: https://github.com/NuGet/NuGet.Client/blob/e082545cbba30ec8dc9b759f2d9beea8aabc6215/src/NuGet.Core/NuGet.Commands/Utility/PackageSourceProviderExtensions.cs#L15-L30, which handles both by name and url.

baronfel commented 1 week ago

@marcpopMSFT this one is ready to go, implemention-wise. We should talk scheduling at some point.