4

I need to compile some f# source files at run-time into an assembly.

At the moment I am using Fsharp.Compiler.CodeDom and it does what I need it to do, however it seems like this library hasn't been maintained. I would like to know, am I using the right one?

Note: I saw some answers to similar questions to this one, but the questions were a few years old.

2
  • 5
    I believe fsharp compiler services allows this - see fsharp.github.io/FSharp.Compiler.Service/compiler.html Commented Apr 14, 2014 at 7:48
  • yes, that works, want to put it as an answer? There was some tweaking regarding the Fsharp.core but it's ok now Commented Apr 15, 2014 at 13:02

1 Answer 1

1

This should actually go to John Palmer.... the spinet 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 it would be cool to see a non fsc.exe option :D

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.