[英]Is it possible to compile C# into IL and decompile the resulting IL into F#?
[英]Compile .IL at runtime C#
我不知道如何在運行時編譯 IL 代碼。 我使用 .NET 核心 3.1,我可以生成一個包含
.assembly extern mscorlib {}
.assembly Hello {}
.module Hello.exe
.class Hello.Program
extends [mscorlib]System.Object
{
.method static void Main(string[] args)
cil managed
{
.entrypoint
ldstr "H"
call void[mscorlib]
System.Console::
Write(string)
ldstr "i"
call void[mscorlib]
System.Console::
Write(string)
ret
}
}
但是我該如何編譯文件呢? 我想在運行時這樣做。 (忽略錯誤的 IL 代碼)
所以,我發現了如何做到這一點。 我從我的 .net 框架文件夾中復制了 ilasm.exe 和 fusion.dll ,然后將字符串保存到文件中,然后我使用 ProcessInfo 運行ilasm file
。 然后輸出了我想要的exe。
對於任何想知道的人,如果您將 verison 替換為框架版本,例如 v4.0.30319,ilasm.exe 位於C:\Windows\Microsoft.NET\Framework\Verison 。
感謝任何試圖提供幫助的人!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.