sdk: dotnet tool restore interactive doesn't prompt for DeviceFlow since .NET 6 SDK

Describe the bug

If I use .NET 5 SDK, and call dotnet tool restore --interactive, I get presented with the DeviceFlow authentication flow from NuGet’s MicrosoftCredentialProvider plugin (https://github.com/microsoft/artifacts-credprovider).

I get something like this:

[CredentialProvider]DeviceFlow: https://XXX.pkgs.visualstudio.com/_packaging/XXX/nuget/v3/index.json
[CredentialProvider]ATTENTION: User interaction required.

**********************************************************************

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXXXXXX to authenticate.

**********************************************************************

However, if I need the same thing in .NET 6 SDK (using 6.0.100), the output is silent, I don’t receive any prompt on the output.

I found a workaround to add --verbosity minimal in the command parameters. But without this, it seems that the default verbosity is quiet which doesn’t include the interactive auth flow prompt.

In .NET 5, the verbosity switch didn’t have any effect for dotnet tool restore, I even created issue #16535. but in .NET 6, suddenly, the verbosity is working. It’s just that the default verbosity is too quiet and is missing the important prompts.

To Reproduce

  • ensure that the tool packages to be restored aren’t in NuGet cache
  • ensure that you use feed that needs MicrosoftCredentialProvider auth (https://github.com/microsoft/artifacts-credprovider), I’m using Azure DevOps Artifacts
  • ensure you don’t have any MicrosoftCredentialProvider token already in cache
  • call dotnet tool restore --interactive
  • expected: prompt for device login
  • actual: no output, program keeps running and waiting for the auth

Further technical details

.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 48
  • Comments: 23 (1 by maintainers)

Most upvoted comments

I’ve had the same issue. As a workaround use the -v diag parameter, at least this worked for me

Actually, our workaround was similar, even --verbosity minimal worked.

It’s as if the default verbosity is quiet, which is too quiet.

I’ve had the same issue. As a workaround use the -v diag parameter, at least this worked for me

Any plans to fix this? My team is also getting this problem since upgrading to .NET 6, the --verbosity minimal works as a workaround, but it’s a bad dev experience that causes devs to waste time wondering what’s going on before finding this workaround

@baronfel - This looks like a regression in .NET 6 and higher. Would it be possible for someone to take a look?

I think I can see in the code why this happens.

This bug fix was added https://github.com/dotnet/sdk/issues/10024 to ensure that it sets verbosity minimal (much like the example above).

https://github.com/dotnet/sdk/blob/a30e465a2e2ea4e2550f319a2dc088daaafe5649/src/Cli/dotnet/commands/dotnet-tool/install/ProjectRestorer.cs#L85

however, where the commands are registered, this is set and then overwritten when the verbosity is registered on the next line. Maybe swapping the lines over would work?

  command.AddOption(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption);
  command.AddOption(VerbosityOption);

https://github.com/dotnet/sdk/blob/2c98ff1381def385256788cfcbaefb3ac32f5778/src/Cli/dotnet/commands/dotnet-tool/restore/ToolRestoreCommandParser.cs#L41

This is the same in the Restore and Update

Hi, do you have ETA when it will be fixed?

I’m getting the same issue, thanks @tompazourek for the workaround.

I’ve experienced this as well on .NET 7.

Running dotnet tool install -g Microsoft.dotnet-interactive in a cmd prompt yields this error, reflecting a package source I have to an Azure DevOps artifacts feed:

Determining projects to restore… C:\Program Files\dotnet\sdk\7.0.102\NuGet.targets(132,5): warning : The plugin credential provider could not acquire cr edentials. Authentication may require manual action. Consider re-running the command with --interactive for dotnet, / p:NuGetInteractive=“true” for MSBuild or removing the -NonInteractive switch for NuGet [C:\Users\whit_\AppData\Local
Temp\2f906456-9768-478a-9646-8be22db8893f\restore.csproj] C:\Users\xyz123\AppData\Local\Temp\2f906456-9768-478a-9646-8be22db8893f\restore.csproj : error NU1301: Unable to load th e service index for source https://pkgs.dev.azure.com/xyx/123/_packaging/abc/nuget/v3/index.json. Failed to restore C:\Users\xyz123\AppData\Local\Temp\2f906456-9768-478a-9646-8be22db8893f\restore.csproj (in 8.27 sec) . The tool package could not be restored. Tool ‘microsoft.dotnet-interactive’ failed to install. This failure may have been caused by:

  • You are attempting to install a preview release and did not use the --version option to specify the version.
  • A package by this name was found, but it was not a .NET tool.
  • The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
  • You mistyped the name of the tool.

For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool

Re-running it with dotnet tool install -g Microsoft.dotnet-interactive --verbosity minimal --interactive prompted me to visit https://microsoft.com/devicelogin and provide a code, which after logging in successfully completed the restore and installed the tool (and I later got an email that a personal access token has been issued on my behalf for the vso.drop_write scope.

I’m pretty sure something like this is the basis for the issue I’m having with using .NET interactive notebooks in VS Code in that I cannot install the NuGet packages because it cannot authenticate to my private Artifact feeds.

https://github.com/dotnet/sdk/issues/22987#issuecomment-1280977262

The bot closed this however any thoughts on my comment which points to what I believe is the issue in the code that is in this code base?

I have started having this issue as well but i am not sure how this has just started, i have had dotnet 6 installed for awhile now and have not had issues.

dotnet tool update -g toolname --interactive

C:\Program Files\dotnet\sdk\6.0.100\NuGet.targets(130,5): error :     [CredentialProvider]Device flow authentication failed. User was presented with device flow, but didn't react within 90 seconds. [C:\Users\username\AppData\Local\Temp\ti1axl1b.0ja\restore.csproj]
C:\Program Files\dotnet\sdk\6.0.100\NuGet.targets(130,5): error : Unable to load the service index for source <Azure Devops Artifact package feed>. [C:\Users\username\AppData\Local\Temp\ti1axl1b.0ja\restore.csproj]
C:\Program Files\dotnet\sdk\6.0.100\NuGet.targets(130,5): error :   Response status code does not indicate success: 401 (Unauthorized). [C:\Users\username\AppData\Local\Temp\ti1axl1b.0ja\restore.csproj]
Tool 'toolname' failed to update due to the following:
The tool package could not be restored.
Tool 'toolname' failed to install. This failure may have been caused by:

* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.

For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool

Any updates?

Same issue here, used @cervesus workaround dotnet tool restore -v n --interactive.


Details:

  1. donet sdk version: 6.0.101
  2. OS: Pop!_OS 22.04 LTS (Ubuntu 22.04)
  3. Arch.: Intel-64
  4. Package source is a private nuget feed from Azure DevOps ( https://pkgs.dev.azure.com/XXXX/nuget/v3/index.json )

@ThisWholeDev Maybe the NuGets you were restoring before were already in the NuGet cache. Or maybe the session token was already present in the CredentialProvider storage (see https://github.com/microsoft/artifacts-credprovider#session-token-cache-locations). It has an expiration time, so it only does the auth flow from time to time, not always.

But yeah, your output looks like something I’m getting too.