Repository navigation
Description
Description
Since #4457 (12.0.0-alpha002), paket install no longer warns about FSharp.Core redirects for a project that declares <TargetFramework>net10.0</TargetFramework>. It still warns when the project inherits its target framework from Directory.Build.props, a common way to set the framework of every project in one place:
F# project .../inherited/Inherited.fsproj references FSharp.Core without specifying "redirects: force" in paket.dependencies. This can lead to "Could not load file or assembly 'FSharp.Core'" errors at runtime. See https://fsprojects.github.io/Paket/dependencies-file.html#Controlling-assembly-binding-redirects for details.
MSBuild resolves this project to net10.0 (dotnet msbuild inherited/Inherited.fsproj -getProperty:TargetFramework prints net10.0), so binding redirects do not apply and the warning is a false positive. In a repository that sets the framework in Directory.Build.props, every F# project gets it.
Versions
Results of the repro below with each version:
| Paket | TargetFramework in the .fsproj |
TargetFramework from Directory.Build.props |
|---|---|---|
| 10.3.1 | no warning | no warning |
| 11.0.0-alpha003, 11.0.1, 12.0.0-alpha001 | warning | warning |
| 12.0.0-alpha002, 12.0.0-alpha005 | no warning | warning |
The warning was introduced in 11.0.0-alpha003 (#4394). 12.0.0-alpha002 (#4457, for #4455) removed it for projects that declare their framework, but not for projects that inherit it.
Cause
ProjectFile.getTargetProfiles only reads the properties of the project file itself: calculatePropertyMap skips Import nodes and never reads Directory.Build.props. When the file has no TargetFramework, TargetFrameworks or TargetFrameworkVersion, it falls back to DotNetFramework FrameworkVersion.V4 (ProjectFile.fs#L1118). V4.IsLegacyVersion is true, so shouldWarnAboutFSharpCoreRedirects treats the project as a .NET Framework one.
Repro
paket.dependencies:
source https://api.nuget.org/v3/index.json
framework: net10.0
storage: none
nuget FSharp.Core
Directory.Build.props:
<Project>
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
</Project>inherited/Inherited.fsproj (framework from Directory.Build.props):
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Compile Include="Lib.fs" />
</ItemGroup>
</Project>explicit/Explicit.fsproj (framework in the project, for comparison):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Lib.fs" />
</ItemGroup>
</Project>inherited/paket.references and explicit/paket.references:
FSharp.Core
Each project folder also holds a Lib.fs containing module Lib.
Run paket install: the warning appears for Inherited.fsproj only.
Environment: Paket 12.0.0-alpha005 (global tool), .NET SDK 10.0.300, Linux.
Suggested fix
Warn only when the project file declares a .NET Framework target, instead of relying on the net40 fallback of GetTargetProfiles(). For example, read TargetFramework, TargetFrameworks and TargetFrameworkVersion in the warning check, and skip the warning when an SDK-style project declares none of them. The fallback itself would stay unchanged.
Activity