microsoft / artifacts-credprovider

The Azure Artifacts Credential Provider enables dotnet, NuGet.exe, and MSBuild to interactively acquire credentials for Azure Artifacts feeds.
MIT License
739 stars 708 forks source link

Broken when referencing a Nuget package in F# interactive #452

Open omcnoe opened 10 months ago

omcnoe commented 10 months ago

In my global Nuget config I have a source that requires authentication. I've authenticated for this source before. dotnet restore works fine and can access packages from this source.

But in F# interactive (fsx script or console) all Nuget package commands like #r "nuget: Microsoft.ABC fail (even for packages that aren't from the problematic source).

Error message: /Users/omcnoe/stdin(1,1): error FS3217: /usr/local/share/dotnet/sdk/7.0.306/NuGet.targets(156,5): warning : The plugin credential provider could not acquire credentials. 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' [/Users/omcnoe/.packagemanagement/nuget/Projects/--SNIP--/Project.fsproj]

Unlike the error message suggests, dotnet fsi --interactive or dotnet --interactive fsi are not valid commands

embetten commented 10 months ago

The dotnet restore command is typically for restoring .csproj files and supports the interactive flag. dotnet fsi is a completely different command and does not look like it supports the --interactive flag (see docs). So the first part of the cred provider error message to use --interactive for 'dotnet' is not applicable in the f# context. However, it looks like this part of the message: or removing -NonInteractive switch for 'NuGet' [/Users/omcnoe/.packagemanagement/nuget/Projects/--SNIP--/Project.fsproj] might be the correct action for f# projects.

Let me know if this resolves the issue.

omcnoe commented 10 months ago

--interactive is relevant for dotnet restore in an .fsproj or .csproj project.

That project file named in the error message isn't my project file - a new random project file is created each time you run dotnet fsi. dotnet fsi is failing to be authenticated with the Nuget source, even though I'm already authenticated - I can access the source in other projects with dotnet restore and don't need to re-authenticate.

The authentication plugin is broken under F# interactive mode - at least for me. I think it's actually a bug.

embetten commented 9 months ago

Can you give more details on where you are running dotnet fsi? Visual Studio and version?

I am able to authenticate and install from an Azure Artifacts feed with dotnet fsi and the cred provider (using the #i and#r commands). This worked in both polygot notebooks, the latest version of Visual Studio, and in Visual studio code. I did find authentication did not work with an older version of visual studio and it looks like VS has a couple of open issues tracking this.

omcnoe commented 9 months ago

I'm on macOS. Using the dotnet sdk installed directly from https://dotnet.microsoft.com/en-us/download

I had sdk 7.0.306, I updated to latest sdk 7.0.401 and it is still not working correctly, still getting same message.

omcnoe commented 9 months ago

I'm running dotnet fsi directly from command line

embetten commented 9 months ago

@omcnoe I was able to repro the issue on a MacOS and spoke with a dev on the f# side. TL;DR this is an issue on the f# side not supporting interactive mode when it calls nuget (msbuild) under the hood. I have created a feature request on their repo.

On my machine running dotnet restore -interactive before dotnet fsi did not require me to reauthenticate and I was able to restore from fsi. From your comments it sounds like this does not work for you? If so, can you ensure you have the most recent version of the cred provider there were some updates to the cache location.

omcnoe commented 9 months ago

I believe I have the most recent version, but I'm not sure. Is the update process just "run the install again"?

embetten commented 9 months ago

Yes, we have an install script for macs to make it easy here. Let me know if this does not resolve the issue.

phil-hodgson commented 8 months ago

@omcnoe Any success with the latest version?

omcnoe commented 7 months ago

@phil-hodgson no, same exact behavior as before

I think the mention of "interactive mode" in the error message is just a red herring. I am already authenticated with this nuget source - dotnet restore elsewhere doesn't require me to re-authenticate.

Shouldn't artifacts-credprovider pick up and use this existing auth? I don't need to re-authenticate using interactive mode inside dotnet fsi - it just has to correctly use whatever existing auth token has already been setup.

johnterickson commented 6 months ago

I don't use F# but if this uses the same underlying msbuild logic then you should be anle to pass in /p:NuGetInteractive=true.

omcnoe commented 6 months ago

Hi John, sadly dotnet fsi does not accept that parameter.

Please see the above comment about NuGet "interactive mode" in the error message being a red herring. I have already authenticated with the nuget source. Other commands like dotnet build that use packages from this source already work fine without requiring me to re-authenticate again.

The problem is that when used by fsi the credential provider is not picking up my existing authentication.

johnterickson commented 6 months ago

Is this related? https://github.com/dotnet/fsharp/issues/10609

github-actions[bot] commented 3 months ago

This issue has had no activity in 90 days. Please comment if it is not actually stale.

omcnoe commented 3 months ago

Yes issue is still present.

github-actions[bot] commented 3 weeks ago

This issue has had no activity in 90 days. Please comment if it is not actually stale.

omcnoe commented 3 weeks ago

This issue still exists.