简体   繁体   中英

How to directly invoke F# compiler on .NET Core?

UPD.:

I want to invoke F# compiler (ie fsc) from .NET Core SDK directly.

I know about dotnet build & co, but I don't want to involve them when I only need to compile a simple problem, ie in cases when fsc file.fs would be enough.

I've tried to search in .NET Core SDK (on my Mac, it was in /usr/local/share/dotnet/sdk/2.2.102/FSharp) and found a fsc.exe file there. Unfortunately, when I try to start it with dotnet /usr/local/share/dotnet/sdk/2.2.102/FSharp/fsc.exe, it gives me an error:

error FS0193: Could not load file or assembly 'Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Env.: macOS, .NET Core 2.2

After install dotnet core ( https://dotnet.microsoft.com/download ) you should be able to build a F# project from the command line.

cd my-fs-project
dotnet build
dotnet run

You probably don't want to call fsc directly, since dotnet build and fsproj is the preferred way of building projects.

If you must though, then it can be found in the SDK files:

dotnet /usr/share/dotnet/sdk/5.0.100/FSharp/fsc.exe

Use dotnet --list-sdks to find the full path to your SDK.

I compile using fsc on Linux in following way.

fsc test.fs --targetprofile:netcore --target:exe --out:test.exe

Then I manually create test.runtimeconfig.json with following content

{
  "runtimeOptions": {
    "tfm": "net5.0",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "5.0.0"
    },
    "rollForwardOnNoCandidateFx": 2
  }
}

Then I was able to run application using dotnet test.exe .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM