DEV Community

Cover image for Getting the "nuget" package manager working in Visual Studio 2019
Jakob Christensen
Jakob Christensen

Posted on

Getting the "nuget" package manager working in Visual Studio 2019

The other day I was working with a collegue on some quick file manipulation with F# interactive (.fsx) in VSCode using the excellent Ionide extension.

We ran into some trouble with Danish letters and encoding and I knew from previously that for reason Visual Studio seems to handle encoding problems in files somewhat better than VSCode. So we decided to try VS instead.

Don't worry, this post is not about encoding 😉

The Problem

However, we did not get very far with VS. We used the new F# 5.0 way of referencing Nuget packages:

#r "nuget: FSharp.Data"
Enter fullscreen mode Exit fullscreen mode

But VS wouldn't let us have our way and it complained:

error FS3216: Package manager key 'nuget' was not registered in
...
[C:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\commonextensions\microsoft\fsharp\Tools]
Enter fullscreen mode Exit fullscreen mode

Intensive searching on the internet provided us with almost no help whatsoever, except for a bit help on Paket's page on fsi integration. Apparently we were the only two people in the world who could not get this stuff working.

The Solution

A bit more searching also revealed that FSharp.DependencyManager.Nuget is required. It is the F# extension manager for Nuget which gives us the coolness of #r "nuget".

That brings us to the final solution:

  1. Install FSharp.DependencyManager.Nuget with nuget.exe.
  2. Copy the file FSharp.DependencyManager.Nuget.dll to the directory mentioned in the error (in our case C:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\commonextensions\microsoft\fsharp\Tools).

That's it. It took us only 2-3 hours to figure that out 🤦‍♂️🤦‍♂️.

I hope this can be helpful to the third person in the world that runs into this problem.

Top comments (5)

Collapse
 
shimmer profile image
Brian Berns • Edited

I suspect this is related to a recent change in Visual Studio that moved the F# interactive executable (fsi.exe) from ...\Microsoft\FSharp to ...\Microsoft\FSharp\Tools. See this SO question for details.

I just checked my VS 16.10 installation and found FSharp.DependencyManager.Nuget.dll in ...\Microsoft\FSharp, even though fsi.exe is now in ...\Microsoft\FSharp\Tools

Collapse
 
simonallfrey profile image
simonallfrey

Thanks Jakob, signed up to dev.to just to express my gratitude for this and your impeachment fish.

I copied the existing FSharp.DependencyManager.Nuget.dll into Tools where fsi.exe resides and got no stack overflow...

I like F# too.

Collapse
 
jeikabu profile image
jeikabu

Recently I too have been faced with what should be simple problems that take hours. There's just too much complexity and "magic" everywhere.

Also, nice to see people using F#, it's a great language!

Collapse
 
t4rzsan profile image
Jakob Christensen

Yes, F# is indeed a great language!

Collapse
 
releek profile image
releek

Thanks for posting this. I have spent a lot of time trying to fix this issue on my own system.

It starts with

error FS3216: Package manager key 'nuget' was not registered in ...

So I downloaded nuget.org/packages/FSharp.Dependen... and extract with 7zip FSharp.DependencyManager.Nuget.dll and place it into C: \ Program Files (x86) \ Microsoft Visual Studio \ 2019 \ Community \ Common7 \ IDE \ CommonExtensions \ Microsoft \ FSharp \ Tools. (I have tried this with a couple of the older dll versions too).

When using F# interactive this generates a new warning:

warning FS3247: The dependency manager extension c: \ program files (x86) \ microsoft visual studio \ 2019 \ community \ common7 \ ide \ commonextensions \ microsoft \ fsharp \ Tools \ FSharp.DependencyManager.Nuget.dll could not be loaded. Message: Could not load file or assembly 'file:///c: \ program files (x86) \ microsoft visual studio \ 2019 \ community \ common7 \ ide \ commonextensions \ microsoft \ fsharp \ Tools \ FSharp.DependencyManager.Nuget.dll' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)

and error:

error FS3216: Package manager key 'nuget' was not registered in [C: \ Users \ *** \ AppData \ Local \ assembly \ dl3 \ 9QMLVPXT.3WC \ J5RNVX75.4Y7 \ bf8bf0ca \ b1c727e6_4d72d701; c: \ program files (x86) \ microsoft visual studio \ 2019 \ community \ common7 \ ide \ commonextensions \ microsoft \ fsharp \ Tools \ ], []. Currently registered:

so I used Brian Berns information and instead copied the dll across from ...\Microsoft\FSharp to ...\Microsoft\FSharp\Tools replacing the version I had downloaded in the description above (and restarting visual studio). Now an F# interactive run generates the error:

Process is terminated due to StackOverflowException.

And now I am utterly stumped. Strangely, the same nuget dependency manager dll is working absolutely fine in VSCode.

Any ideas?