我正在开发一个项目,我们正在使用DLR将Racket语言移植到.NET.
我们构建一个表达式树并调用CompileToMethod()
Method:
相关的可执行发射代码:(取自如何将表达式树保存为新的可执行磁盘文件的主要入口点?)
//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");
Run Code Online (Sandbox Code Playgroud)
我们有我们的运行时库Runtime_rkt.dll
,它包含相关的运行时类型转换,后备对象等.
当我们将Foo.exe
和Runtime_rkt.dll
在同一目录下,一切工作正常.我们遇到的问题是当我们(显然)将运行时库移动到其他地方时.最终我们想要C:\Windows\Microsoft.NET\assembly\GAC_MSIL
像IronPython一样安装它.[使用GAC解决]
[编辑]额外的新问题有没有办法我们可以将所有运行时方法静态编译成可执行文件?