Próbuję rozpocząć program podstawowy, aby dynamicznie skompilować i uruchomić kod f #. Próbuję uruchomić następujący kod:"CompileAssemblyFromSource" w kodzie # powerPackDom
open System
open System.CodeDom.Compiler
open Microsoft.FSharp.Compiler.CodeDom
// Our (very simple) code string consisting of just one function: unit -> string
let codeString =
"module Synthetic.Code\n let syntheticFunction() = \"I've been compiled on the fly!\""
// Assembly path to keep compiled code
let synthAssemblyPath = "synthetic.dll"
let CompileFSharpCode(codeString, synthAssemblyPath) =
use provider = new FSharpCodeProvider()
let options = CompilerParameters([||], synthAssemblyPath)
let result = provider.CompileAssemblyFromSource(options, [|codeString|])
// If we missed anything, let compiler show us what's the problem
if result.Errors.Count <> 0 then
for i = 0 to result.Errors.Count - 1 do
printfn "%A" (result.Errors.Item(i).ErrorText)
result.Errors.Count = 0
if CompileFSharpCode(codeString, synthAssemblyPath) then
let synthAssembly = Reflection.Assembly.LoadFrom(synthAssemblyPath)
let synthMethod = synthAssembly.GetType("Synthetic.Code").GetMethod("syntheticFunction")
printfn "Success: %A" (synthMethod.Invoke(null, null))
else
failwith "Compilation failed"
z tej strony: http://infsharpmajor.wordpress.com/2012/04/01/how-to-dynamically-synthesize-executable-f-code-from-text/
Problem mam jest z następującej linii:
let result = provider.CompileAssemblyFromSource(options, [|codeString|])
Gdzie mogę uzyskać wyjątek: The System cannot find the file specified.
Zawarłem wymagane referencje Fsharp.compiler.codeDom.dll
i Fsharp.compiler.dll
i nie jestem pewien, co jeszcze może być problemem. Obecnie próbuję uzyskać kod źródłowy dll dla CodeDom
z codeplex i przejść przez to, ale to zaoszczędziłoby mi dużo bólu głowy, jeśli ktoś jest w stanie zobaczyć jakiś problem, który przeoczyłem.
Dziękuję za poświęcony czas, -Alper
Poniższy link zawiera minimalny kod do kompilacji w pamięci: http://stackoverflow.com/questions/15313404/in-application-script-hosting-how-does-tryfsharp-org-work –
Ten problem wydaje się związany http: //stackoverflow.com/questions/2733415/fsharp-core-sigdata-not-found-alongside-fsharpcore –