dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.88k stars 783 forks source link

FSI #r Supports NuGet interactive. #16057

Open embetten opened 1 year ago

embetten commented 1 year ago

Is your feature request related to a problem? Please describe.

When trying to restore a package from a private Azure DevOps Azure Artifacts feed in dotnet fsi on MacOS, feed authentication using the artifacts-credprovider fails. I believe it fails because fsi does not allow NuGet to be run in interactive mode. If the user was able to propagate an interactive flag to MS build/NuGet and display the output, the azure credprovider would be able to provide credentials in fsi.

Describe the solution you'd like

A desirable solution would allow the user to pass the interactive flag from the fsi restore command to MS build/NuGet and allow NuGet/MS build to write the necessary output to the fsi console window.   A command flag such as: fsi > #r -interactive ...

or the nuget env variable FORCE_NUGET_EXE_INTERACTIVE .

Describe alternatives you've considered

A work around I have found at the moment is to fill the local cred provider cache with a dotnet restore -interactive command prior to the fsi command. But it would be nice to not have to do this extra step before hand.

Additional context

When the artifacts-credprovider is invoked by NuGet during a restore, the cred provider tries various authentication methods available on the device to get the credentials. Sometimes the only available authentication methods require interaction such as a pop-up login window or device code flow. The NuGet, Dotnet and MS build CLIs allow to pass the interactive flag to enable the interactive mode.

I have also tried using the nuget env variable FORCE_NUGET_EXE_INTERACTIVE , however this does not seem to work either. I suspect it fails because fsi takes over the console and does not allow NuGet to write the device code flow output.

Repro steps:

  1. On a MacOs, install the latest dotnet version, and install the latest artifacts-credprovider.
  2. invoke dotnet fsi
  3. Run #i "nuget:<replace with Azure Artifacts feed url> (see https://learn.microsoft.com/en-us/azure/devops/artifacts/get-started-nuget?view=azure-devops&tabs=windows).
  4. Run: #r "nuget:Newtonsoft.json

You should get this error message:

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]

omcnoe commented 9 months ago

I'm not sure this issue is actually accurate.

The problem I have is that I can't reference any NuGet packages from dotnet fsi when I have an authentication required NuGet source. In my case I have already authenticated with this NuGet source. Other dotnet commands like dotnet build that use this source work without re-authenticating or using cred provider interactive mode.

dotnet fsi doesn't need to pass the interactive mode flag through and let me authenticate again. It just needs to correctly use the authentication that has already been done for this source.

omcnoe commented 9 months ago

This issue is just a duplicate of #11392