使用Codedom在运行时编译F#源代码?

4
我需要在运行时将一些f#源文件编译成一个程序集。 目前我正在使用Fsharp.Compiler.CodeDom,它可以完成我的需求,但似乎这个库已经没有维护了。 我想知道,我是否使用了正确的库? 注意:我看到了一些类似问题的答案,但那些问题是几年前的。

5
我相信F#编译器服务可以做到这一点-请参见http://fsharp.github.io/FSharp.Compiler.Service/compiler.html - John Palmer
是的,那个可行,想把它作为答案吗?关于Fsharp.core还需要进行一些调整,但现在没问题了。 - roundcrisis
1个回答

1
这实际上应该发给John Palmer...他链接中的小钢琴基本上可以正常工作。
[<EntryPoint>]
let main argv = 
    printfn "%A" argv

    let scs = SimpleSourceCodeServices();
    let fn = Path.GetTempFileName();
    let fn2 = Path.ChangeExtension(fn, ".fs");
    let fn3 = Path.ChangeExtension(fn, ".dll");

    File.WriteAllText(fn2, """ 
module File1
  let seven =
           3 + 4
        """);

    let errors1, exitCode1 = scs.Compile([| "fsc.exe"; "-o"; fn3; "-a"; fn2 |])
    let ex = File.Exists(fn3)
    printfn "File %s exists: %b" fn3 ex

我必须承认,看到一个非 fsc.exe 选项会很酷 :D


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接