简体   繁体   中英

NuGet issues when installing same package to multiple F# projects in solution

Here's the solution layout:

  • FSharpNuGetTest (sln)
    • FirstService (F# 3.1 console project, .NET 4.5/4.5.2)
    • SecondService (F# 3.1 console project, .NET 4.5/4.5.2)

For the sake of an argument, let's say I want to install TopShelf from NuGet to both of those services. The error happens no matter the library, someone else had very similar issue not that long ago , but it seems I can actually reliably reproduce it.

NuGet Package Manager version: 2.8.60318.734

After opening NuGet package manager console in VS2013.4 Community Edition:

PM> Install-Package Topshelf -ProjectName FirstService
Installing 'Topshelf 3.1.4'.
(... snip - license stuff ...)
Successfully installed 'Topshelf 3.1.4'.
Adding 'Topshelf 3.1.4' to FirstService.
Successfully added 'Topshelf 3.1.4' to FirstService.

Perfect. Now let's try the same thing with the other service:

PM> Install-Package Topshelf -ProjectName SecondService
'Topshelf 3.1.4' already installed.
Adding 'Topshelf 3.1.4' to SecondService.
No exact match found for removing reference 'Topshelf'. Trying case-insensitive search...
Failed to find match for removing reference 'Topshelf'.
Install-Package : Failed to add reference to 'Topshelf'.
At line:1 char:16
+ Install-Package <<<<  Topshelf
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

Ooops...

I encountered it (again) when

  1. Trying to install XUnit/NUnit to multiple F# test projects in a solution.
  2. Most recently, when trying to install Akka.FSharp to multiple F# projects in a solution.

Any ideas how to fix it...?

It only happened to me with multiple F# projects - never had any issues with C# projects.

My bandaid solution is to copy & paste references from one .fsproj file to another. Update-Package even seems to be working after that operation. That doesn't change the fact that it's a hack and not how solution management is supposed to work, especially when reinstall is needed - then you have to copy & paste all <Reference> elements from one .fsproj (the one that actually gets everything installed) to every other all over again, because NuGet package installation dies on subsequent projects...

Edit

It seems that brute force might work here - after ca 4 tries, the package got installed to the second service application (?!). That makes no sense...

I just hope I won't have to do that on CI server.

It's kind of a half-answer, but here it goes.

As I noted in the edit, brute-forcing seems to work. If it doesn't work the first time, just spamming Install-Package makes it work on the second (or third, or fourth...) try.

Weird...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM