Compile F # source while working with Codedom?

I need to compile some f # source files at runtime into an assembly.

I am currently using Fsharp.Compiler.CodeDom and it does what I need, but it seems this hasn library was not supported. I would like to know if I am using the right one?

Note. I saw several answers to similar questions to this, but the questions were several years old.

+4
source share
1 answer

That should really go to John Palmer ... the spinach from his link basically just works

[<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

I have to admit that it would be great to see the non fsc.exe option: D

+1
source

Source: https://habr.com/ru/post/1536401/


All Articles