6
我正在研究一個項目,我們正在使用DLR將球拍語言移植到.NET。靜態鏈接和編譯運行時w/compiletoMethod()表達式樹
我們建立一個表達式樹,並調用CompileToMethod()
方法:
相關的可執行排放代碼:(從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");
我們有我們的運行時庫Runtime_rkt.dll
其中包含有關運行時類型轉換,支持對象等。
當我們將Foo.exe
和Runtime_rkt.dll
放在同一個目錄中時,一切正常。我們遇到的問題是我們(顯然)將運行時庫移到其他地方。最終我們想要像IronPython那樣在C:\Windows\Microsoft.NET\assembly\GAC_MSIL
中安裝它。 [使用GAC解決]
附加pts的新問題有什麼辦法可以將所有運行時方法靜態編譯到可執行文件中嗎?
我認爲,如果[將其正確添加到GAC](http://msdn.microsoft.com/zh-cn/library/dkkx7f79)(不只是將其複製到目錄中),它應該可以正常工作。 – svick
祝你好運。但表達式通常會產生相當糟糕的代碼:(如果我必須再次執行IronScheme,我會使用CCI而不是DLR。 – leppie
@leppie這不是我想聽到的:(。我們切換到CCI有點晚瞭如果我們決定重新做這個,那麼謝謝你的信息。 –