fsprojects / Paket

A dependency manager for .NET with support for NuGet packages and Git repositories.
https://fsprojects.github.io/Paket/
MIT License
2.02k stars 520 forks source link

Implicit FSharp.Core reference is not considered #3972

Open uladz-zubrycki opened 3 years ago

uladz-zubrycki commented 3 years ago

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

  1. Execute dotnet new console -lang F# -n Repro

  2. Execute dotnet build Reference to FSharp.Core is there yet. Check out contents of project.assets file in the obj folder, you'll see "FSharp.Core/5.0.0" under the "libraries" node. Library is copied to bin folder and is present as reference in the output Repro.dll.

  3. Execute paket init (Suppose that we have it globally)

  4. Add any package to the .fsproj file. Let it be NewtonSoft.Json

    • Execute paket add NewtonSoft.Json
    • Create paket references file containing the only line, which is NewtonSoft.Json
  5. Execute paket install You'll see F# project Repro\Repro.fsproj does not reference FSharp.Core.

  6. Execute dotnet build FSharp.Core reference is gone: it's not present in project.assets anymore, it's not present in the newly generated Repro.fsproj.paket.props, it's not copied to the bin folder, but is still referenced by the generated dll, though could not be found.

  7. Execute dotnet run You'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.

despairblue commented 3 years ago

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.

abelbraaksma commented 2 years ago

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.