Why does adding some packages break my code?

I noticed that adding packages sometimes breaks my code. Functions like Seq.replicate

and List.take

that work get red squiggly lines and the program no longer works. Here is a detailed procedure that should replicate the problem (I'm using VS Community Edition 2017

):

1) Create a project.

2) Program.fs

contains the code:

[<EntryPoint>]
let main argv =
    printfn "%A" argv
    0 // return an integer exit code

      

3) Add two lines of code like this:

[<EntryPoint>]
let main argv =
    let repla = Seq.replicate 10 "A"
    printfn "%A" (repla |> List.ofSeq |> List.take 5)
    printfn "%A" argv
    0 // return an integer exit code

      

3) Click Ctrl+F5

, the program runs without problems.

4) Right click References

on Solution Explorer

. Click Manage Nuget Packages...

.

5) Click Browse

.

6) Find Newtonsoft.Json

and install it.

7) Click Ctrl+F5

, the program runs without problems. Console prints

["A"; "A"; "A"; "A"; "A"]
[||]

      

8) Continue as in steps 4 through 6 and install the package MathNet.Numerics

with Nuget

.

9) Click Ctrl+F5

, the program runs without problems. Console prints

["A"; "A"; "A"; "A"; "A"] [||]

10) Proceed in the same way as in steps 4 to 6 and install the package MathNet.Numerics.FSharp

using Nuget

.

11) Go to the tab Program.fs

. Scary red squiggly lines appeared under the Seq.replicate and

List.take`.

12) Click Ctrl+F5

. A dialog box appears with the following message:

There were build errors. Would you like to continue and run the last successful build?

      

Questions:

a) What exactly is going on?

b) Is this an isolated case related to a problem in MathNet.Numerics.FSharp

or a specific combination of installed packages or the order in which they were installed? Or is this a common problem?

c) Is it possible to avoid this problem by using Nuget?

d) If not, can this problem be avoided by installing other means (not Nuget)?

+3


source to share


2 answers


Ok, I think the FP issues are somewhat correct. I would give up editing the fsproj file manually. Also, the comments are very relevant, Paket is a great tool that makes it easy to manage dependencies both in VS and in code. So, here's a very simple two-part answer where: a) you can actually use your solution using a nugget, and without manually editing the project file, and b) quickly put in how to use paket for VS.

This issue where some package downloads and an old dependency that messed up other code happens from time to time and probably due to the strategy of relying on the minimum viable version. Your problem is somewhat similar to this question. Q: Why can't I get myself to work?

Here's the simplest solution using only nugget:

  • Open a new solution with fsharp console project
  • At this point, your Fsharp.Core in VS2017 will be 4.1:

enter image description here

  1. Now add Mathnet.Numerics.Fsharp via nugget:

enter image description here

Now unfortunately you got downgraded to F # 3.1

  1. This isn't good, so just get Fsharp.Core via nugget!

enter image description here

  1. And voila, you are back to a working solution without having to edit fsproj. Basically all you had to do was add the Fsharp.Core package. You could also change the .NET Framework setting in properties and port it to .NET 4.7 using Fsharp 4.1:

enter image description here

Now for part 2 of the answer with Paket (by the way, the Paket plugin has just been updated and I tested it and it works great). You can use it as a nugget replacement or edit files directly. You really need to work with two files paket.dependencies

at the solution root and the paket.references

project root. Paket.lock

... Here's a two-step process to get you started. Take the project you just made and from the Tools menu in VS select Paket Dependencies Manager

, execute Initialize Paket

, then execute Convert From Nuget

:



enter image description here

With this, you can manage your dependencies with nuget or use paket if you like. Then I will add Newtonsoft.JSON to the links. Double click on the file paket.dependencies

and add the following line: nuget Newtonsoft.Json 10.0.3 restriction: >= net452

you actually need Newtonsoft.Json, but we don't want to download the whole interweb called .NetCore. Also, add this line to paket.references

(you can just click on it in the Project Explorer) Newtonsoft.Json

. And run Tools | Package | Installation:

Paket.dependencies:

enter image description here

Paket.references:

enter image description here

And run the package installer:

enter image description here

And you will have Newtonsoft.JSON installed. Usually you don't need to specify the version of the framework constraint, however it has a preview package which you may not need and also I suppose you don't need the .netcore dependencies.

You can right click and try to install this package from the Add Package menu, but you will run into dependency errors.

enter image description here

enter image description here

+3


source


MathNet.Numerics.FSharp

has a dependency on FSharp.Core.3.1.2.5

which replaces the current version FSharp.Core

you are using. Being pretty old 3.1.2.5

lacks many features.

This happens with other popular libraries F#

like FsCheck

. I usually change the link to the newest version FSharp.Core

as it needs to be backward compatible.

To do this, I unload the project F#

and update the link FSharp.Core

in the project file:



<Reference Include="FSharp.Core">
  <Name>FSharp.Core</Name>
  <AssemblyName>FSharp.Core.dll</AssemblyName>
  <HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\$(TargetFSharpCoreVersion)\FSharp.Core.dll</HintPath>
</Reference>

      

Then I reload the project.

Since this is a rather clumsy procedure, we hope that more discerning users post a better solution.

+6


source







All Articles