NU1605 when building an F# app referencing an F# NuGet package
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
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](https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/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](https://github.com/ForNeVeR/vahter-bot/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`:
```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.)_
Contributor guide
Assessment
This issue has not been assessed yet.