F # How to set up a FAKE project that can use FsUnit

I am trying to set up a basic FAKE F # project that can run FsUnit, but I cannot figure out how to solve the Method not found: 'Void FsUnit.TopLevelOperators.should(Microsoft.FSharp.Core.FSharpFunc`2<!!0,!!1>, !!0, System.Object)' errors Method not found: 'Void FsUnit.TopLevelOperators.should(Microsoft.FSharp.Core.FSharpFunc`2<!!0,!!1>, !!0, System.Object)' .

I read the following posts, which seem to be related to each other, but I apparently still don't understand it:

I created a JunkTest library JunkTest with the following setup:

paket.dependencies

 source https://www.nuget.org/api/v2 nuget FAKE nuget FSharp.Core nuget FsUnit nuget NUnit nuget NUnit.Console 

paket.references

 FSharp.Core FsUnit NUnit 

JunkTest.fs

 module JunkTest open FsUnit open NUnit.Framework [<Test>] let ``Example Test`` () = 1 |> should equal 1 // this does not work //Assert.That(1, Is.EqualTo(1)) // this works (NUnit) 

build.fsx (corresponding part)

 Target "Test" (fun _ -> !! (buildDir + "JunkTest.dll") |> NUnit3 (fun p -> {p with OutputDir = "TestResults" } ) ) 

Exit

I see that FSharp.Core.dll is copied from the local packages directory: Copying file from "c:\Users\dangets\code\exercism\fsharp\dgt\packages\FSharp.Core\lib\net40\FSharp.Core.dll" to "c:\Users\dangets\code\exercism\fsharp\dgt\build\FSharp.Core.dll".

And executing nunit3-console: c:\Users\dangets\code\exercism\fsharp\dgt\packages\NUnit.ConsoleRunner\tools\nunit3-console.exe "--noheader" "--output=TestResults" "c:\Users\dangets\code\exercism\fsharp\dgt\build\JunkTest.dll"

I tried to add the app.config file with the root directory of the test project as follows, but it does not seem to solve the problem (NOTE: I am not using Visual Studio - do I have to do something special for the project to include the app.config file?):

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration> 

Any help is appreciated.

EDIT:. The solution was that I did not properly configure the app.config file to be included in the assembly. All the answers that said β€œjust add this to your app.config file” did not help me because VSCode does not automatically add it to the fsproj file.

The part I added:

 <None Include="App.config" /> 

In an ItemGroup that contains the other lines <Compile Include=Foo.fs> .

+6
source share
2 answers

This is due to a mismatch in the version of FSharp.Core . See, your application refers to one version of FSharp.Core and FsUnit refers to another version. This means that the type FSharpFunc<_,_> will be different (from different assemblies) for you and FsUnit , which in turn means that the should function exported by FsUnit is not the same function as your code because it has a parameter of a different type.

Here is the bindingRedirect . You absolutely correctly added it to app.config , but from your question about whether you are doing this correctly, I get a suspicion that you cannot. The thing with app.config is that this is not really a program configuration. Rather, it is the source code for program configuration. At compile time, this file will be copied to bin\Debug\Your.Project.dll.config , and only after that it will be loaded at run time. If you did not add this file to the fsproj project fsproj (which I suspect may be the case), then it will not be copied to the right place at build time and thus will not be loaded at runtime.

Another reason it still doesn't work may be because you specified the wrong version of FSharp.Core in your app.config file. This brings me to the next point.

Creating this file manually is a little fragile: when you upgrade FSharp.Core to a new version (or Paket does it for you), you may forget to fix it in app.config , and even if you do not, it is a bit of a hassle. But the package can help you with this: if you add redirects: on options to your paket.dependencies file, Paket will add bindingRedirect cool to your app.config automatically:

 source https://www.nuget.org/api/v2 nuget FAKE nuget FSharp.Core redirects: on nuget FsUnit nuget NUnit nuget NUnit.Console 
+4
source

This is similar to the version mismatch of FSharp.Core.

The NuGet package uses ships with FSharp.Core 4.4 (not 4.3.1). I recommend changing the binding redirection to use 4.4:

 <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.4.0.0" /> 
+1
source

Source: https://habr.com/ru/post/1014344/


All Articles