小编Sco*_*uer的帖子

静态链接和编译Runtime w/compiletoMethod()表达式树

我正在开发一个项目,我们正在使用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.exeRuntime_rkt.dll在同一目录下,一切工作正常.我们遇到的问题是当我们(显然)将运行时库移动到其他地方时.最终我们想要C:\Windows\Microsoft.NET\assembly\GAC_MSIL像IronPython一样安装它.[使用GAC解决]

[编辑]额外的新问题有没有办法我们可以将所有运行时方法静态编译成可执行文件?

c# delegates runtime expression-trees dynamic-assemblies

6
推荐指数
1
解决办法
664
查看次数