Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let compileScript(state : State) =
if(state.hasStartupScript = false) then Success(state, [])
else
try
if File.Exists(outputAssembly) then
File.Delete(outputAssembly)
let provider = new FSharpCodeProvider()
let params'= CompilerParameters()
params'.GenerateExecutable <- false
params'.OutputAssembly <- outputAssembly
params'.IncludeDebugInformation <- true
params'.ReferencedAssemblies.AddRange(defaultAssemblies)
params'.ReferencedAssemblies.AddRange(state.referencedAssemblies)
params'.GenerateInMemory <- true
params'.WarningLevel <- 3
params'.TreatWarningsAsErrors <- false
let compiledResults = provider.CompileAssemblyFromSource(params', state.sourceCode)
if compiledResults.Errors.Count > 0 then
//TODO fix later
let erros = [for error in compiledResults.Errors do error.ErrorText ]
let errorMessages = List.append ["Failed to compile startup script"] erros
Failure(errorMessages)
else
let state = { state with compiledCode = Some(compiledResults.CompiledAssembly) }
Success(state, ["Startup script compiled successfully."])
with
| exn -> Failure([sprintf "Failed to compile startup script. %s" exn.Message])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.