I am working on a project in which we port Racket to .NET using DLR.
We create an expression tree and call the CompileToMethod() method:
Corresponding executable emission code: (taken from How to save the expression tree as the main entry point to the new disk executable? )
//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_rkt.dll runtime Runtime_rkt.dll that contains the corresponding runtime type conversions, support objects, etc.
When we Foo.exe and Runtime_rkt.dll in the same directory, everything works fine. The problem we are facing is when we (obviously) move the runtime library to another location. Ultimately, we will want to install it in C:\Windows\Microsoft.NET\assembly\GAC_MSIL , as IronPython does. [Decided to use the GAC]
[edit] New question for extra points. Is there a way to statically compile all executables into an executable?
source share