diff --git a/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs b/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs index d5f2a2ce7781..5a3b00907319 100644 --- a/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs +++ b/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs @@ -114,8 +114,9 @@ public override int Execute() // other feeds, but this is probably OK. var downloadPackageLocation = new PackageLocation( nugetConfig: _configFile != null ? new(_configFile) : null, - sourceFeedOverrides: [packageSource.Source], - additionalFeeds: _addSource); + sourceFeedOverrides: _sources, + additionalFeeds: _addSource, + packageSourceOverrides: [packageSource]); toolPackage = _toolPackageDownloader.InstallPackage( downloadPackageLocation, diff --git a/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs b/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs index 7768f6f5d68b..8f19a15380c3 100644 --- a/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs +++ b/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs @@ -468,6 +468,11 @@ private List LoadDefaultSources(PackageId packageId, PackageSourc public IEnumerable LoadNuGetSources(PackageId packageId, PackageSourceLocation packageSourceLocation = null, PackageSourceMapping packageSourceMapping = null) { + if (packageSourceLocation?.PackageSourceOverrides?.Any() ?? false) + { + return packageSourceLocation.PackageSourceOverrides; + } + var sources = (packageSourceLocation?.SourceFeedOverrides.Any() ?? false) ? LoadOverrideSources(packageSourceLocation) : LoadDefaultSources(packageId, packageSourceLocation, packageSourceMapping); diff --git a/src/Cli/dotnet/NugetPackageDownloader/PackageSourceLocation.cs b/src/Cli/dotnet/NugetPackageDownloader/PackageSourceLocation.cs index ed70adeaf924..883965ca1539 100644 --- a/src/Cli/dotnet/NugetPackageDownloader/PackageSourceLocation.cs +++ b/src/Cli/dotnet/NugetPackageDownloader/PackageSourceLocation.cs @@ -4,6 +4,7 @@ #nullable disable using Microsoft.Extensions.EnvironmentAbstractions; +using NuGet.Configuration; namespace Microsoft.DotNet.Cli.NuGetPackageDownloader; @@ -14,7 +15,8 @@ public PackageSourceLocation( DirectoryPath? rootConfigDirectory = null, string[] sourceFeedOverrides = null, string[] additionalSourceFeeds = null, - string basePath = null) + string basePath = null, + PackageSource[] packageSourceOverrides = null) { basePath = basePath ?? Directory.GetCurrentDirectory(); @@ -24,12 +26,15 @@ public PackageSourceLocation( SourceFeedOverrides = ExpandLocalFeed(sourceFeedOverrides, basePath); // Feeds to be using in addition to config AdditionalSourceFeed = ExpandLocalFeed(additionalSourceFeeds, basePath); + // Feeds that have already been evaluated and selected to be used + PackageSourceOverrides = packageSourceOverrides; } public FilePath? NugetConfig { get; } public DirectoryPath? RootConfigDirectory { get; } public string[] SourceFeedOverrides { get; private set; } public string[] AdditionalSourceFeed { get; private set; } + public PackageSource[] PackageSourceOverrides { get; private set; } private static string[] ExpandLocalFeed(string[] sourceFeedOverrides, string basePath) { diff --git a/src/Cli/dotnet/ToolPackage/PackageLocation.cs b/src/Cli/dotnet/ToolPackage/PackageLocation.cs index b102097a1c2d..c33daeca15e3 100644 --- a/src/Cli/dotnet/ToolPackage/PackageLocation.cs +++ b/src/Cli/dotnet/ToolPackage/PackageLocation.cs @@ -4,6 +4,7 @@ #nullable disable using Microsoft.Extensions.EnvironmentAbstractions; +using NuGet.Configuration; namespace Microsoft.DotNet.Cli.ToolPackage; @@ -11,10 +12,12 @@ internal class PackageLocation( FilePath? nugetConfig = null, DirectoryPath? rootConfigDirectory = null, string[] additionalFeeds = null, - string[] sourceFeedOverrides = null) + string[] sourceFeedOverrides = null, + PackageSource[] packageSourceOverrides = null) { public FilePath? NugetConfig { get; } = nugetConfig; public DirectoryPath? RootConfigDirectory { get; } = rootConfigDirectory; public string[] AdditionalFeeds { get; } = additionalFeeds ?? []; public string[] SourceFeedOverrides { get; } = sourceFeedOverrides ?? []; + public PackageSource[] PackageSourceOverrides { get; } = packageSourceOverrides ?? []; } diff --git a/src/Cli/dotnet/ToolPackage/ToolPackageDownloaderBase.cs b/src/Cli/dotnet/ToolPackage/ToolPackageDownloaderBase.cs index 28a8e7973846..20cc2c93a1ef 100644 --- a/src/Cli/dotnet/ToolPackage/ToolPackageDownloaderBase.cs +++ b/src/Cli/dotnet/ToolPackage/ToolPackageDownloaderBase.cs @@ -110,7 +110,7 @@ public IToolPackage InstallPackage(PackageLocation packageLocation, PackageId pa verbosity, restoreActionConfig); - var packageSourceLocation = new PackageSourceLocation(packageLocation.NugetConfig, packageLocation.RootConfigDirectory, packageLocation.SourceFeedOverrides, packageLocation.AdditionalFeeds, _currentWorkingDirectory); + var packageSourceLocation = new PackageSourceLocation(packageLocation.NugetConfig, packageLocation.RootConfigDirectory, packageLocation.SourceFeedOverrides, packageLocation.AdditionalFeeds, _currentWorkingDirectory, packageLocation.PackageSourceOverrides); NuGetVersion packageVersion = nugetPackageDownloader.GetBestPackageVersionAsync(packageId, versionRange, packageSourceLocation).GetAwaiter().GetResult();