"dotnet restore --interactive" doesn't work with Azure Artifacts

Viewed 6629

I have a newly installed Windows 10 machine with the .NET Core SDK 3.0.100. I have a project with it's nuget.config file containing (among other reference) a reference to an Azure Artifacts nuget feed, and i'd like to access credentials to this feed interactively. It's worth to point out that i'd like to use command line to achieve this. My IDE of choice is Jetbrains Rider and not Visual Studio (for this particular question i'm not sure that matters though).

I have downloaded the Azure Artifacts Credential Provider by running a powershell command (Invoke-WebRequest...) and installed it - what seems - successfully. Now I have a nuget plugin on my computer that's supposed to help me retrieve credentials for azure artifact feeds.

What i do expect to work is that running dotnet restore --interactive should prompt me to enter credentials, but it doesnt. It doesnt prompt at all, and just complains that it cannot find the packages.

I've tried this other times too, both on MacOS and Windows with my colleagues, and it always seem to be some problems related to this. Any ideas what i'm doing wrong?

Thanks for your help!

4 Answers

I'll answer my own question as it might help someone else.

When I tried dotnet restore --configfile .\.nuget\NuGet.Config --interactive it did prompt me. I could login in and everything worked!

I'm not sure why, but it seems that just running dotnet restore --interactive doesn't pick the correct nuget sources - or at least not the ones I have defined in .\.nuget\NuGet.Config in my local project. And therefore the credential provider (obviously) won't prompt me for anything. I haven't found any details on whether this is the expected behaviour or a bug.

There is another option in case you cannot make dotnet restore --interactive work out of the box when you add the nuget.config file to your project.

You can clear all the nuget local caches.

The easiest way of doing this is using the following command:

dotnet nuget locals all --clear

After some time, when all caches are cleared, you can run dotnet restore --interactive again, and hopefully the Azure Artifacts Credential Provider should show you instructions for authentication through device code.

With the option posted by @Robson Rocha about clear all the nuget local caches, I could got the credential instructions but nevertheless after authentication I kept getting the error:

warn : The plugin credential provider could not acquire credentials. ...
error: Response status code does not indicate success: 401 (Unauthorized).

I solved the problem in my Windows dev environment creating an Azure Personal Access Token with permissions “Scopes: Custom defined, Packaging: Read” and setting it in the %AppData% Nuget folder:

C:\Users\{UserName}\AppData\Roaming\NuGet\NuGet.Config

nuget.config reference - packageSourceCredentials

<packageSourceCredentials>
  <MyPackageSourceKey>
    <add key="Username" value="myUserName" />
    <add key="ClearTextPassword" value="TheAzurePersonalAccessToken" />
  </MyPackageSourceKey>
</packageSourceCredentials>

Because the %AppData% Nuget folder is per user and it is outside of the repo folder, the credentials are kept secure per user and we avoid committing them into the repo.

Related