I am working on a project where we're porting the Racket Language to .NET using DLR.
We build up an expression tree and invoke the CompileToMethod()
Method:
Relevant executable emission code: (taken from How to Save an Expression Tree as the Main Entry Point to a New Executable Disk File?)
//Wrap the program into a block expression
Expression code = Expression.Block(new ParameterExpression[] { env, voidSingleton}, program);
var asmName = new AssemblyName("Foo");
var asmBuilder = AssemblyBuilder.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave);
var moduleBuilder = asmBuilder.DefineDynamicModule("Foo", "Foo.exe");
var typeBuilder = moduleBuilder.DefineType("Program", TypeAttributes.Public);
var methodBuilder = typeBuilder.DefineMethod("Main",
MethodAttributes.Static, typeof(void), new[] { typeof(string) });
Expression.Lambda<Action>(code).CompileToMethod(methodBuilder);
typeBuilder.CreateType();
asmBuilder.SetEntryPoint(methodBuilder);
asmBuilder.Save("Foo.exe");
we have our runtime library Runtime_rkt.dll
which contains relevant runtime type conversions, backing objects, etc.
When we place Foo.exe
and Runtime_rkt.dll
in the same directory everything works fine. The issue we're having is when we (obviously) move the runtime library to else where. Ultimately we will want to install it in C:\Windows\Microsoft.NET\assembly\GAC_MSIL
like IronPython does. [Solved using GAC]
[edit] New Question for Extra pts Is there any way we can statically compile all the runtime methods into the executable?