F#5 compiler + net20 target framework = build error
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
As it says -- this was observed with a project that worked happily under SDK 3.1.403 after moving to 5.0.100
Not sure if an oversight or something deliberate, but it means there's something that can be done in current C# that can't be done with current F# any more.
**Repro steps**
We can still target `net20` in a C# program with the net5.0 SDK and it "just works"
```
dotnet new console -lang C#
```
edit to set
```
net20
```
Add reference assemblies
```
dotnet add package Microsoft.NETFramework.ReferenceAssemblies.net20
```
and run
```
>dotnet run
Hello World!
```
Doing the same for F#
```
dotnet new console -lang F#
```
edit to set
```
net20
```
`dotnet add`ing either of net necessary packages `Microsoft.NETFramework.ReferenceAssemblies.net20` or `FSharp.Core` v4.1.18 (about the latest with a `net20` offering) fail with messages like
```
info : Package 'FSharp.Core' is compatible with all the specified frameworks in project '$(ProjectPath)'.
error: Error while performing Update for package 'FSharp.Core'. Cannot edit items in imported files -
```
Manually editing to add the packages (equivalent to taking an pre-existing functioning-at-3.1 project and using the new tooling)
```
all
runtime; build; native; contentfiles; analyzers; buildtransitive
```
and doing `dotnet run` gives
```
FSC : error FS0078: Unable to find the file 'System.Numerics.dll' in any of↔ ~\.nuget\packages\microsoft.netframework.referenceassemblies.net20\1.0.0\build\.NETFramework\v2.0↔ $(ProjectDir)↔ C:\Program Files\dotnet\sdk\5.0.100\FSharp\ [$(ProjectDir)\$(ProjectName).fsproj]
The build failed. Fix the build errors and run again.
```
**Expected behavior**
Anything we can do with C# we can do in F#
**Actual behavior**
As above
**Known workarounds**
Use an older F# compiler
```
dotnet add package FSharp.Compiler.Tools -v 10.2.3
```
and build with MSBuild (plain `dotnet run` gives an interesting error, to wit `The file extension of 'C:\Program Files\dotnet\sdk\5.0.100\FSharp\fsc.exe' is not recognized.` )
```
msbuild $(ProjectPath)
```
whereupon the program can be run without building
```
>dotnet run --no-build
Hello world from F#
```
**Related information**
* Operating system: Windows 10 Home, 2004 build
* .NET Runtime kind (.NET Core, .NET Framework, Mono): .net sdk 5.0
* Editing Tools (e.g. Visual Studio Version, Visual Studio): notepad suffices here
Contributor guide
Assessment
This issue has not been assessed yet.