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.92k stars 786 forks source link

Referencing packages in F# Interactive doesn't work when connected to a feed requiring authentication #11392

Open vsfeedback opened 3 years ago

vsfeedback commented 3 years ago

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] According to the official documentation, it should be possible to reference NuGet packages from an F# script file:

#r "nuget: Newtonsoft.Json"
open Newtonsoft.Json

let data = {| Name = "Don Syme"; Occupation = "F# Creator" |}
JsonConvert.SerializeObject(data)

When I try to do this, however, it doesn't work. The editor is full of red squiggly lines, the error list contains five errors, and when I send the code to F# Interactive (Alt + Enter), it prints this error message:

Reactors.fsx(1,1): error FS3217: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(131,5): warning : The plugin credential provider could not acquire credentials. Authentication may require manual action. Consider re-running the command with --interactive fordotnet, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch forNuGet[C:\Users\mark\AppData\Local\Temp\nuget\20272--3928d5e7-1194-4146-a20d-a5f0dd5e8910\Project.fsproj]

It's not clear how to proceed from here.


Original Comments

Feedback Bot on 3/28/2021, 11:37 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

ploeh commented 3 years ago

Based on a hint by Kevin Ransom in the original issue report, I tried to turn off the other NuGet feeds I've configured in Visual Studio. That seems to make the error go away.

image

That was really not obvious to me, but can be used as a workaround.

cartermp commented 3 years ago

This is related to https://github.com/dotnet/fsharp/issues/10609 which is tracking the ability to specify credentials in a script for an authenticated feed.

But the core issue here is that when you specify one of the sources that requires authentication, a NuGet error is generated since you're not authenticated for scripting. That could arguably be a bug.

ploeh commented 3 years ago

To be clear, I didn't need a NuGet package from the authenticated feed that I had configured; I just wanted a normal NuGet package off of nuget.org.

Even so, the mere presence of a NuGet feed that requires authentication is enough to completely break this functionality.

ploeh commented 3 years ago

I don't know if this is related, but today, I'm trying this:

#r @"nuget: FSharpPlus"

open FSharpPlus

let maybeXs: Option<List<int>> = Some [1]

Even with all other NuGet sources removed, when I send this to F# Interactive, I get this:

~vsAC87.fsx(1,1): error FS3216: Package manager key 'nuget' was not registered in [C:\Users\mark\AppData\Local\assembly\dl3\OGA45T4X.NBA\NVCC20B1.RWG\f7d9b153\c20c92ba_7358d701; c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\fsharp\Tools\], []. Currently registered: 

~vsAC87.fsx(1,1): error FS3217: Processing of a script fragment has stopped because an exception has been raised
Happypig375 commented 3 years ago

@ploeh You're hitting https://github.com/dotnet/fsharp/issues/11622 which is fixed in VS16.11.

nodakai commented 3 years ago

Even so, the mere presence of a NuGet feed that requires authentication is enough to completely break this functionality.

This is really bad, I had to add a custom nuget.config to keep a private GitHub Nuget source out of touch of .fsx scripts. Disabling them didn't work, but that'd have a wider impact to an entire repository anyways, so I'll stick with my workaround for a while. If we want authenticated sources to be ignored just as a quick mitigation, what can we do?

https://github.com/dotnet/fsharp/blob/eb1337f218275da5294b5fbab2cf77f35ca5f717/src/fsharp/FSharp.DependencyManager.Nuget/FSharp.DependencyManager.Utilities.fs#L152 🤷 The resulting, ephemeral .fsproj has to say "this and that RestoreAdditionalProjectSources might fail (due to missing configs) but that alone shouldn't fail the entire build." I don't know if such a property is exposed to us/fsi.

cadull commented 1 year ago

For me, unticking the authenticated package source in Visual Studio fixed the Ionide F#: Run script and FSI: Send File options, but not the highlighted errors in the editor. Adding a nuget.config file in the script folder to remove the authenticated source resolved the remaining issues.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <remove key="name of authenticated source" />
    </packageSources>
</configuration>
omcnoe commented 11 months ago

In my case, I am already authenticated with the NuGet source. Other commands like dotnet build in projects that use this source don't require re-authenticating. Why can dotnet fsi not re-use this already setup authentication for the source?