-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FSharp.Compiler.Service uses latest TargetFramework when compiling scripts rather than environment. #14289
Comments
hm, @KevinRansom does this ring a bell to you? |
Regarding that dll missing error, we were getting a similar problem over in ProjInfo. (Just pointing it out as it might help diagnosing what's going on here) |
looking |
We are noticing something similar with homebrew, which apparently uninstalls the old sdk version by default (scary, but true). That doesn't seem to be the case here, but it gives the same kind of errors. The big difference being that |
Yes, this is definitely an issue. The behavior generating default references does not do what is expected. I did a bunch of cleanup around that code a month or two ago, I may have broken something. Although it may also have been broken a lot longer than that. Here is a complete straightforward repro: It produces this output:
System.Runtime should be 6.0.0.0 because of the presence of the global.json file with this specification:
|
Before 7.0 hit the market, I noticed that if you have Not sure it helps now, but to me it kinda confirms that this was broken longer ago. I blamed it on the RC status and never gave it much thought. |
Okay I have improved the repro slightly to make the issue more clear:
|
It may not be a regression then, indeed it may never have worked entirely as expected. It would be hard to see in an environment where we are not transitioning between two tfms net6.0 ==> net7.0. However it is a feature that was designed and is supposed to work. I'll mark this as impact-medium and will work on finding a decent fix |
Thanks for looking into this and producing a proper repro. I got to 11pm last night and couldn't handle creating a new project. |
When I use FSharpChecker.Create(keepAssemblyContents = true).ParseAndCheckFileInProject for my target parsing project which is running in dotnet 7, I also got some error:
|
@KevinRansom There seems to be a workaround to this issue, using a solution posted here: |
Not sure if this is a bug or a feature request.
I am using FSharp.Compiler.Service to compile user created F# scripts. Up until today, the code was working as expected however after I updated to .NET 7 the script compilation succeeds but attempting to load/reflect into the script fails with:
After some investigation what seems to be happening is when
FSharpChecker.Compile
is given an fsx file, it implicitly creates an fsproj file with theTargetFramework=net7.0
(based on the latest SDK installed?). The rest of my solution is targetingnet6.0
so it can't find the correct version ofSystem.Runtime
.Repro steps
A concise repro is not simple. The key parameters are described below.
As an attempted workaround I placed a global.json into the runtime directory:
Then with some scripts I get a compiler error. To cause this behaviour the script must have some dependencies to trigger the creation of a .fsproj on disk.
#r "nuget: FSharp.Data, 5.0.2"
seems to be sufficient for this. Simple scripts produce the same System.Runtime exception from above.Expected behavior
My initially expected behavior is that selecting a particular version of
FSharp.Compiler.Service
(I tried with 41.0.6 and 41.0.7) corresponding toFSharp.Core
6.0.6 and 6.0.7 would set theTargetFramework=net6.0
andFSharp.Compiler.Service
42.7.1 would set theTargetFramework=net7.0
.I would have also expected the compiler to consider the presence of global.json and set the TargetFramework based on that.
I searched extensively to see if there was some way to instruct
FSharpChecker
on what TargetFramework to use e.g. with compiler args. Possibly there could be an overload toCompile
or new method added toFSharpChecker
which provides some direct control over the implicitly generated fsproj file.Known workarounds
None tested. Expect that uninstalling the latest .NET so that only .NET 6 SDKs were present on the system would succeed. My update to .NET 7 happened as part of automatic updates to Visual Studio.
Related information
Provide any related information (optional):
dotnet --list-sdks
5.0.104 [C:\Program Files\dotnet\sdk]
6.0.111 [C:\Program Files\dotnet\sdk]
6.0.202 [C:\Program Files\dotnet\sdk]
6.0.203 [C:\Program Files\dotnet\sdk]
6.0.306 [C:\Program Files\dotnet\sdk]
7.0.100 [C:\Program Files\dotnet\sdk]
The text was updated successfully, but these errors were encountered: