Skip to content
Closed
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
9 changes: 5 additions & 4 deletions src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
Expand Down Expand Up @@ -128,13 +128,14 @@ public override int Execute()
}

// We've already determined which source we will use and displayed that in a confirmation message to the user.
// So set the package location here to override the source feeds to just the source we already resolved to.
// So set the package location here to override the source feeds to the explicit source we already resolved to.
// This does mean that we won't work with feeds that have a primary package but where the RID-specific packages are on
// 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,
explicitSource: packageSource);

toolPackage = _toolPackageDownloader.InstallPackage(
downloadPackageLocation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ private List<PackageSource> LoadDefaultSources(PackageId packageId, PackageSourc

public IEnumerable<PackageSource> LoadNuGetSources(PackageId packageId, PackageSourceLocation packageSourceLocation = null, PackageSourceMapping packageSourceMapping = null)
{
if (packageSourceLocation?.ExplicitSource != null)
{
return [packageSourceLocation.ExplicitSource];
}

var sources = (packageSourceLocation?.SourceFeedOverrides.Any() ?? false) ?
LoadOverrideSources(packageSourceLocation) :
LoadDefaultSources(packageId, packageSourceLocation, packageSourceMapping);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#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 explicitSource = null)
{
basePath = basePath ?? Directory.GetCurrentDirectory();

Expand All @@ -24,12 +26,14 @@ public PackageSourceLocation(
SourceFeedOverrides = ExpandLocalFeed(sourceFeedOverrides, basePath);
// Feeds to be using in addition to config
AdditionalSourceFeed = ExpandLocalFeed(additionalSourceFeeds, basePath);
ExplicitSource = explicitSource;
}

public FilePath? NugetConfig { get; }
public DirectoryPath? RootConfigDirectory { get; }
public string[] SourceFeedOverrides { get; private set; }
public string[] AdditionalSourceFeed { get; private set; }
public PackageSource ExplicitSource { get; private set; }

private static string[] ExpandLocalFeed(string[] sourceFeedOverrides, string basePath)
{
Expand Down
7 changes: 5 additions & 2 deletions src/Cli/dotnet/ToolPackage/PackageLocation.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#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 explicitSource = null)
{
public FilePath? NugetConfig { get; } = nugetConfig;
public DirectoryPath? RootConfigDirectory { get; } = rootConfigDirectory;
public string[] AdditionalFeeds { get; } = additionalFeeds ?? [];
public string[] SourceFeedOverrides { get; } = sourceFeedOverrides ?? [];
public PackageSource ExplicitSource { get; } = explicitSource;
}
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.ExplicitSource);

NuGetVersion packageVersion = nugetPackageDownloader.GetBestPackageVersionAsync(packageId, versionRange, packageSourceLocation).GetAwaiter().GetResult();

Expand Down