Skip to content

Commit

Permalink
Support Interactive without setting verbosity explicitly in dotnet to…
Browse files Browse the repository at this point in the history
…ol restore Fixes #22987 (#45312)

Fixes #22987

We don't currently pass a RestoreActionConfig from ToolRestoreCommand to the ToolPackageDownloader (and by extension the NuGetPackageDownloader) we actually use to install the tool. This corrects that error.

Additionally, the default verbosity is quiet. When the interactive flag is passed, that effectively suppresses it. This increases the default verbosity from quiet to minimal when interactive is requested.
  • Loading branch information
Forgind authored Dec 20, 2024
1 parent 0ee30b8 commit fcba596
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ bool TryGetPackageMetadata(
try
{
SourceRepository repository = GetSourceRepository(source);
DefaultCredentialServiceUtility.SetupDefaultCredentialService(new NuGetConsoleLogger(), !_restoreActionConfig.Interactive);
PackageMetadataResource resource = await repository
.GetResourceAsync<PackageMetadataResource>(cancellationToken).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.CommandLine;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.NuGetPackageDownloader;
using Microsoft.DotNet.Cli.ToolPackage;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ToolManifest;
Expand All @@ -24,6 +25,7 @@ internal class ToolRestoreCommand : CommandBase
private readonly string[] _sources;
private readonly IToolPackageDownloader _toolPackageDownloader;
private readonly VerbosityOptions _verbosity;
private readonly RestoreActionConfig _restoreActionConfig;

public ToolRestoreCommand(
ParseResult result,
Expand Down Expand Up @@ -61,6 +63,15 @@ public ToolRestoreCommand(
_configFilePath = result.GetValue(ToolRestoreCommandParser.ConfigOption);
_sources = result.GetValue(ToolRestoreCommandParser.AddSourceOption);
_verbosity = result.GetValue(ToolRestoreCommandParser.VerbosityOption);
if (!result.HasOption(ToolRestoreCommandParser.VerbosityOption) && result.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption))
{
_verbosity = VerbosityOptions.minimal;
}

_restoreActionConfig = new RestoreActionConfig(DisableParallel: result.GetValue(ToolCommandRestorePassThroughOptions.DisableParallelOption),
NoCache: result.GetValue(ToolCommandRestorePassThroughOptions.NoCacheOption) || result.GetValue(ToolCommandRestorePassThroughOptions.NoHttpCacheOption),
IgnoreFailedSources: result.GetValue(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption),
Interactive: result.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption));
}

public override int Execute()
Expand Down Expand Up @@ -130,7 +141,11 @@ private ToolRestoreResult InstallPackages(
nugetConfig: configFile,
additionalFeeds: _sources,
rootConfigDirectory: package.FirstEffectDirectory),
package.PackageId, verbosity: _verbosity, ToVersionRangeWithOnlyOneVersion(package.Version), targetFramework
package.PackageId,
verbosity: _verbosity,
ToVersionRangeWithOnlyOneVersion(package.Version),
targetFramework,
restoreActionConfig: _restoreActionConfig
);

if (!ManifestCommandMatchesActualInPackage(package.CommandNames, [toolPackage.Command]))
Expand Down

0 comments on commit fcba596

Please sign in to comment.