Question

Let's say we have a fsi script like this:

#r "System.Core.dll"
let script = "Console.WriteLine(\"Hello, World!\")"
// fsi script ???

We can use #load to invoke fsi on a file, but is it possible to somehow invoke fsi on an in-memory string without writing that to a file first?

The use-case is an API compatibility tester: given a dll, I would like to create a script that invocations all its public APIs and compile that script against a different version of the same dll.

I could always write the generated script to disk, but it would be much cleaner if I could run it directly.

Était-ce utile?

La solution

The tasks of kind you outlined in your question may be performed with tools provided within Microsoft.FSharp.Compiler.Interactive namespace, in particular, with the help of type FsiEvaluationSession of Microsoft.FSharp.Compiler.Interactive.Shell.

This gist authored by Ryan Riley demoes exactly your scenario using a thin wrapper type FSharpEngine over FsiEvaluationSession, making programmatic use of fsi as convenient as:

....
let engine = new FSharpEngine()
engine.Execute("<some F# code>") |> processOutput
....
engine.Dispose()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top