fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

NU1605 when building an F# app referencing an F# NuGet package

Open ForNeVeR opened this issue 1 year ago • 0 comments

When building an F# application that uses a NuGet package also developed using F#, if the SDK used in the app is a bit outdated, then a warning NU1605 will be generated.

This is even more serious in cases when warnings-as-errors are enforced in the project.

Filed per request from @vzarytovskii.

Repro steps

  1. Have .NET SDK 8.0.302 installed.
  2. Clone commit 00a516141ab7a43f86a524ad151f4431f5eafc81 from https://github.com/ForNeVeR/vahter-bot
  3. dotnet build

Expected behavior

The project should build normally.

Actual behavior

A lot of errors like this one:

G:\Projects\vahter-bot\src\VahterBanBot\VahterBanBot.fsproj : error NU1605: Warning As Error: Detected package downgrade: FSharp.Core from 8.0.301 to 8.0.300. Reference t
he package directly from the project to select a different version.  [G:\Projects\vahter-bot\vahter-ban-bot.sln]

Known workarounds

One of these:

  • do not use warnings as errors;
  • update the .NET SDK used in the application to a newer version, the one that bundles FSharp.Core 8.0.301;
  • do not use implicit FSharp.Core in the application.

Why this happens?

There are several affecting factors.

  1. The library the project uses, Funogram, happens to be built using a fresh version of .NET SDK, thus implicitly receiving a reference to FSharp.Core 8.0.301.
  2. The project itself also gets an FSharp.Core reference implicitly from the .NET SDK it uses, though it has an older version (.NET SDK 8.0.302) pinned by the global.json:
    {
      "sdk": {
        "version": "8.0.302"
      }
    }
    
  3. The project has warnings-as-errors enabled. If it didn't, then AFAIK it would silently downgrade the library (in practice, most likely causing no problems, though the idea sounds quite problematic in general).

Possible Solutions?

So far, I come up with the following ideas.

  • Do not recommend people to build NuGet packages with implicit FSharp.Core reference, advice to reference it explicitly.
    • Change the default library project template? (Most likely not, it will get too complex.)
    • Issue a warning when performing dotnet pack on a project with implicit reference? (Possible.)
  • Modify F# SDK to auto-upgrade FSharp.Core (at least up to a patch version number) if it detects that some of the used dependencies bring a newer version. (I am not sure this is possible to do, though it would be neat.)

ForNeVeR avatar Oct 19 '24 18:10 ForNeVeR