Skip to content

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

Open

Description

@vsfeedback

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 for dotnet, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for NuGet [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)

Activity

  1. ploeh commented on Apr 8, 2021

    @ploeh
    Contributor

    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.

  2. cartermp commented on Apr 9, 2021

    @cartermp
    Contributor

    This is related to #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.

  3. changed the title [-]Referencing packages in F# Interactive doesn't work[/-] [+]Referencing packages in F# Interactive doesn't work when connected to a feed requiring authentication[/+] on Apr 9, 2021
  4. added
    Impact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.
    on Apr 9, 2021
  5. added this to the Backlog milestone on Apr 9, 2021
  6. ploeh commented on Apr 9, 2021

    @ploeh
    Contributor

    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.

  7. ploeh commented on Jul 22, 2021

    @ploeh
    Contributor

    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
    
  8. Happypig375 commented on Jul 23, 2021

    @Happypig375
    Member

    @ploeh You're hitting #11622 which is fixed in VS16.11.

  9. nodakai commented on Oct 29, 2021

    @nodakai

    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?

    executeTool (getDotnetHostPath()) "nuget list source --format short" scriptDirectory timeout

    🤷
    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.

  10. cadull commented on Jul 31, 2023

    @cadull

    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>
    
  11. omcnoe commented on Dec 15, 2023

    @omcnoe

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FSIBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions