Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit FSharp.Core reference is not considered #3972

Open
uladz-zubrycki opened this issue Dec 25, 2020 · 2 comments
Open

Implicit FSharp.Core reference is not considered #3972

uladz-zubrycki opened this issue Dec 25, 2020 · 2 comments

Comments

@uladz-zubrycki
Copy link

uladz-zubrycki commented Dec 25, 2020

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
  1. Execute paket install
    You'll see F# project Repro\Repro.fsproj does not reference FSharp.Core.

  2. 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.

  3. 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
Copy link

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants