fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

What's the best practice for using F# with Central Package Management

Open ericstj opened this issue 6 months ago • 5 comments

I noticed my FSProj broke when enabling CPM.

I see that's because the implicit reference to FSharp.Core is not added in this case.

What am I supposed to do to fix this? Should I be adding a PackageReference to all fsprojs and listing the PackageVersion in my central Directory.Packages.props? Should I use the FSCorePackageVersion that's defined by the SDK?

ericstj avatar Jun 12 '25 20:06 ericstj

@ericstj that is actually a very interesting question.

Ideally the compiling SDK should determine the FSharp.Core package, because the compiler and F# Core are co-developed, new language features almost always rely on the latest FSharp.Core.

If you want to use CPM set DisableImplicitFSharpCoreReference to true. and add a specific FSharp.Core to load in your project file. A good starting version is the value of FSCorePackageVersion which does match the version shipped with that SDK.

KevinRansom avatar Jun 13 '25 18:06 KevinRansom

In agreement with @KevinRansom - here is the practice I follow: In Directory.Packages.props:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
    <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="FSharp.Core" Version="9.0.300" />
  </ItemGroup>
</Project>

In Directory.Build.props:

<Project>
    <PropertyGroup>
        <DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="FSharp.Core" />
    </ItemGroup>
</Project>

Lanayx avatar Jun 15 '25 00:06 Lanayx

@Lanayx This doesn't have to be in a Directory.Build.props it can be but shouldn't be necessary. <DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>

KevinRansom avatar Jun 16 '25 02:06 KevinRansom

@KevinRansom agree, but it makes a big sense for Central Package Management. The idea is to manage all packages centrally including FSharp.Core and avoid duplicating this lines in every project.

Lanayx avatar Jun 16 '25 03:06 Lanayx

<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>

This is an optional line) https://github.com/dotnet/fsharp/pull/13920

<PackageReference Include="FSharp.Core" />

There may be non-fsharp projects, it is better to add a check for fsharp)

rstm-sf avatar Jun 17 '25 08:06 rstm-sf