Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ private List<PackageSource> LoadDefaultSources(PackageId packageId, PackageSourc

public IEnumerable<PackageSource> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#nullable disable

using Microsoft.Extensions.EnvironmentAbstractions;
using NuGet.Configuration;

namespace Microsoft.DotNet.Cli.NuGetPackageDownloader;

Expand All @@ -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();

Expand All @@ -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)
{
Expand Down
5 changes: 4 additions & 1 deletion src/Cli/dotnet/ToolPackage/PackageLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
#nullable disable

using Microsoft.Extensions.EnvironmentAbstractions;
using NuGet.Configuration;

namespace Microsoft.DotNet.Cli.ToolPackage;

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 ?? [];
}
2 changes: 1 addition & 1 deletion src/Cli/dotnet/ToolPackage/ToolPackageDownloaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading