运行 CoreCLR 中的 F#

Running F# in CoreCLR

我编译了CoreCLR and CoreFX as described here。基本上这行得通,我可以编译 运行 C# code targeting CoreCLR.
下一步是尝试编译和 运行ning F# 代码。所以我将 FSharp.Core 3.1.2.1 添加到项目中并使用以下命令编译了一个示例应用程序:

fsc ^
--noframework ^
--targetprofile:netcore ^
/r:packages\System.Runtime.4.0.20-beta-22703\lib\contract\System.Runtime.dll ^
/r:packages\System.Reflection.4.0.10-beta-22703\lib\contract\System.Reflection.dll ^
/r:packages\System.Collections.4.0.10-beta-22703\lib\contract\System.Collections.dll ^
/r:packages\System.Diagnostics.Debug.4.0.10-beta-22703\lib\contract\System.Diagnostics.Debug.dll ^
/r:packages\System.IO.FileSystem.4.0.0-beta-22703\lib\contract\System.IO.FileSystem.dll ^
/r:packages\System.Linq.Expressions.4.0.10-beta-22703\lib\contract\System.Linq.Expressions.dll ^
/r:packages\System.Console.4.0.0-beta-22703\lib\contract\System.Console.dll ^
/r:packages\System.Runtime.Extensions.4.0.10-beta-22703\lib\contract\System.Runtime.Extensions.dll ^
/r:packages\System.Runtime.InteropServices.4.0.20-beta-22703\lib\contract\System.Runtime.InteropServices.dll ^
/r:packages\System.Text.Encoding.4.0.10-beta-22703\lib\contract\System.Text.Encoding.dll ^
/r:packages\System.Text.RegularExpressions.4.0.10-beta-22703\lib\contract\System.Text.RegularExpressions.dll ^
/r:packages\System.Threading.Overlapped.4.0.0-beta-22703\lib\contract\System.Threading.Overlapped.dll ^
/r:packages\System.Threading.ThreadPool.4.0.10-beta-22703\lib\contract\System.Threading.ThreadPool.dll ^
/r:packages\FSharp.Core.3.1.2.1\lib\portable-net45+netcore45+MonoAndroid1+MonoTouch1\FSharp.Core.dll ^
/out:runtime\HelloWorld.exe HelloWorld.fs

如您所见,我是针对 FSharp.Core 的 Profile7 构建的。 当我 运行 应用程序时,语句 let test = sprintf "Hello, world" 失败并出现以下异常:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.FSharp.Core.PrintfImpl.PrintfBuilderStack..ctor()
   at Microsoft.FSharp.Core.PrintfImpl.PrintfBuilder`3..ctor()
   at Microsoft.FSharp.Core.PrintfImpl.Cache`4.generate(String fmt)
   at Microsoft.FSharp.Core.PrintfImpl.f@4277-43[T,TState,TResidue,TResult](String key, Unit unitVar0)
   at Microsoft.FSharp.Core.PrintfImpl.Cache`4.get(String key)
   at Microsoft.FSharp.Core.PrintfImpl.Cache`4.Get(PrintfFormat`4 key)
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThen[TResult,T](FSharpFunc`2 continutation, PrintfFormat`4 format)
   at HelloWorld.main(String[] args)

我也讨论过这个 here 但我不知道我做错了什么。 我包含了错误版本的 FSharp.Core 吗?配置文件 7 should work.

在撰写本文时(2015 年 4 月),F# 尚未移植到完全支持 CoreCLR / CoreFX。

CoreCLR and CoreFX 目前在开发过程中正在进行大量更改和改进。在接下来的几个月里,流失率会降低,稳定性会迅速提高,但此时在 CoreCLR/FX 上建造任何实质性建筑都将类似于在流沙上建造摩天大楼。

Mono v.next,目前用于在 [LI|U]N[U|I]X 上构建和 运行 F#,它也正在经历很多变化,因为它取代了大型Mono 平台和框架的块,以及来自 CoreCLR 和 CoreFX 的程序集和代码。

您可能想要跟踪 Visual F# issue #387 以了解进度。

您可能还想跟踪 Visual F# issue #336,其中讨论了在 CoreCLR 上支持 F# 以进行 x 平台工作。

更新 1:

现在 F# 4.0 已经发布,团队正在进行一系列新工作:https://github.com/Microsoft/visualfsharp/issues/563

这些工作项目中的关键是向 F# 添加 CoreCLR 支持:https://github.com/Microsoft/visualfsharp/issues/499