[Mono-dev] Embedding Mono into C++

Robert Jordan robertj at gmx.net
Sat Jul 24 12:04:01 EDT 2010


On 24.07.2010 15:11, Frank Fuchs wrote:
>
> On a related note is there a way to invoke the mcs compiler from within the code to compile some .cs file.
> Of course one could try to invoke mcs with a system call or ExecuteProcess but is there something more convenient?
> As far as I read about the evaluator it seems not to so well suited for this purpose since i don't want/ need line-by-line action or repl.


Look at System.CodeDom.Compiler.CodeDomProvider. Something like that:

CodeDomProvider provider = CodeDomProvider.CreateProvider ("C#");
CompilerParameters parms = new CompilerParameters ();
params.GenerateExecutable = true;
params.OutputAssembly = "test.exe";
provider.CompileAssemblyFromFile (parms, new string [] {"test.cs"});

Then wrap this code in a handy C# method that can be
conveniently mono_runtime_invoke()-ed from C++.

Robert



More information about the Mono-devel-list mailing list