Skip to content

Don't warn about FSharp.Core redirects for projects that inherit their framework - #4487

Merged
fpellet merged 3 commits into
masterfrom
fix/fsharp-core-warning
Nov 8, 2026
Merged

fpellet merged 3 commits into
masterfrom
fix/fsharp-core-warning

Conversation

@fpellet

@fpellet fpellet commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Closes #4485

Since #4457, paket install no longer warns about missing redirects: force for FSharp.Core in a project that declares net10.0, but it still warned for an SDK project that takes its framework from Directory.Build.props, a common way to set the framework of every project in one place. Binding redirects don't apply to such a project, so the warning was a false positive.

Cause

Paket only reads the properties of the project file: it doesn't read Directory.Build.props.

  • A project that inherits its framework declares none, and ProjectFile.getTargetProfiles falls back to net40, which shouldWarnAboutFSharpCoreRedirects (InstallProcess.fs) takes for .NET Framework.
  • A TargetFramework set to a property defined there, as $(DefaultTargetFramework), expands to an empty string, which FrameworkDetection reads as net10, .NET Framework 1.0. The same goes for an empty entry of TargetFrameworks, as in net8.0; .

Fix

  • ProjectFile.getDeclaredTargetProfiles (GetDeclaredTargetProfiles()) returns the profiles that the project file declares, without the net40 fallback. getTargetProfiles is defined on top of it and keeps the fallback.
  • Empty framework values are ignored, so such a project declares no framework. Where Paket needs the framework of the project, as for framework: auto-detect, paket pack or binding redirects, it falls back to net40 like for a project without framework, instead of net10.
  • The warning checks the declared profiles: when the project file declares none, Paket can't tell and doesn't warn.

As suggested in the issue, Paket keeps reading the XML of the project only, since evaluating each project with MSBuild costs about 0.8 s. A project that inherits net48 from Directory.Build.props is therefore no longer warned, and one with net$(Version) still is, as before.

Tests

  • TargetFrameworkSpecs: the declared profiles of an SDK project without framework (none, while GetTargetProfiles keeps net40), with $(DefaultTargetFramework), with net8.0; and with net48.
  • BindingRedirect: the i004485-fsharp-core-warning-inherited-framework scenario has a project that inherits its framework from Directory.Build.props, one that sets it through a property defined there, and one that declares net48. paket install warns about the net48 project only; without the fix, it warned about all three.

getDeclaredTargetProfiles returns the profiles of the project file without
the net40 fallback of getTargetProfiles, so that a caller can tell a project
that declares .NET Framework 4.0 from one whose framework Paket can't read,
as when it comes from Directory.Build.props.
Paket doesn't read Directory.Build.props, so a TargetFramework set to a
property defined there, as $(DefaultTargetFramework), expands to an empty
string, which FrameworkDetection reads as net10. The project file then
declares no framework, and getTargetProfiles falls back to net40 as for a
project without TargetFramework.

The same goes for an empty entry of TargetFrameworks, as the space after
the last separator of `net8.0; `, which survives the split and becomes ""
once trimmed.
… its framework

Paket doesn't read Directory.Build.props, so a project that takes its
framework from there declares none in its file, and the net40 fallback of
getTargetProfiles took it for a .NET Framework project. The warning now
checks the profiles that the project file declares, and stays silent when
there is none.

Fixes #4485
@fpellet
fpellet merged commit c0a4d76 into master Nov 8, 2026
12 checks passed
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

Successfully merging this pull request may close these issues.

FSharp.Core "redirects: force" warning still fires for net5.0+ projects that inherit TargetFramework from Directory.Build.props

1 participant