Static Linking and Compilation Runtime w / compiletoMethod ()

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?

+6
source share
1 answer
  • After you put the runtime library in the GAC, everything should work, right? Why don't you do it right now?
  • Try to explain how the embedded executable will look for a runtime library
  • Look at ILMerge
  • Take a look at this year's .net MS compilation build. Not only is compilation with native code declared, but it also includes all libraries and CLRs in the exe file.
  • You can always subscribe to the AppDomain.AssemblyResolve event. Obviously, you will have to compile this subscription into your generated exe file.
  • You can configure the folders in which the CLR looks for DLLs in the configuration file.
0
source

All Articles