Implicit FSharp.Core reference is not considered
Description
If I create new FSharp project, FSharp.Core library is referenced implicitly unless DisableImplicitFSharpCoreReference is set to true, but it isn't by default. Look for FSCorePackageVersion at \dotnet\sdk\5.0.101\FSharp\Microsoft.FSharp.NetSdk.props for details.
I will lose this reference by using paket for package restore after installing any package to the project.
Repro steps
Dotnet version: 5.0.101 Paket version: 5.257.0
-
Execute
dotnet new console -lang F# -n Repro -
Execute
dotnet buildReference toFSharp.Coreis there yet. Check out contents ofproject.assetsfile in theobjfolder, you'll see"FSharp.Core/5.0.0"under the"libraries"node. Library is copied tobinfolder and is present as reference in the outputRepro.dll. -
Execute
paket init(Suppose that we have it globally) -
Add any package to the
.fsprojfile. Let it beNewtonSoft.Json
- Execute
paket add NewtonSoft.Json - Create
paket referencesfile containing the only line, which isNewtonSoft.Json
-
Execute
paket installYou'll seeF# project Repro\Repro.fsproj does not reference FSharp.Core. -
Execute
dotnet buildFSharp.Corereference is gone: it's not present inproject.assetsanymore, it's not present in the newly generatedRepro.fsproj.paket.props, it's not copied to thebinfolder, but is still referenced by the generateddll, though could not be found. -
Execute
dotnet runYou'll see
Unhandled exception.
Cannot print exception string because Exception.ToString() failed.
Instead of expected
Hello world from F#
Expected behavior
FSharp.Core package is referenced and copied to the bin folder.
Actual behavior
FSharp.Core is missing, causing runtime error.
Known workarounds
Add FSharp.Core manually by running paket add FSharp.Core and putting it to the project's paket.references file.
Just leaving this here in case somebody finds this issue and is facing the same cause that I did:
I had (because the dotnet paket init created it like this) this in my paket.dependencies:
source https://api.nuget.org/v3/index.json
storage: none
framework: netcoreapp3.1, netstandard2.0, netstandard2.1
Changing this to
source https://api.nuget.org/v3/index.json
storage: none
framework: auto-detect
made things work.
I'm just running into this very same issue and after being puzzled for a little while (I removed the FSharp.Core explicit references, but I kept having compile errors) I noticed this line in the .paket\Paket.Restore.targets files:
<!-- Disable automagic references for F# DotNet SDK -->
<!-- This will not do anything for other project types -->
<!-- see https://github.com/fsharp/fslang-design/blob/master/tooling/FST-1002-fsharp-in-dotnet-sdk.md -->
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
This is probably because I created this project using the instructions of https://github.com/fsprojects/FSharp.TypeProviders.SDK/ (i.e. the "official" SDK for type providers), but those templates do not work well with VS 2022 (it just errors on loading the project). It also fixes the FSharp.Core version to 4.7-ish.
Removing it, only just lead to Paket putting it back. Not sure what's going on here or how to fix it... Sorry for blurring the thread with the comment, it's just in case someone has a solution or comes across the cause of this bug.