Mono Mkbundle是否制作本地代码

tec*_*hno 6 c# mono monodevelop xamarin-studio

单声道生成的正常EXE是在IL中.我想生成Native Executable,使用mkbundle生成本机Exe还是应该使用Mono AOT.

mba*_*emy 15

是的,mkbundle生成本机可执行文件.例如,在Linux上,这是我的.NET程序集:

file Agent.exe
Agent.exe: PE32 executable (console) Intel 80386, Mono/.Net assembly, for MS Windows
Run Code Online (Sandbox Code Playgroud)

我告诉mkbundle将其编译为本机可执行文件(这里我必须添加Common.dll,它是我的Agent.exe程序集的依赖项):

mkbundle --deps -o Agent Agent.exe Common.dll
   OS is: Linux
   Sources: 3 Auto-dependencies: True
   embedding: Agent/bin/Debug/Agent.exe
   embedding: Agent/bin/Debug/Common.dll
   embedding: /usr/lib/mono/4.5/mscorlib.dll
   embedding: /usr/lib/mono/gac/System.Runtime.Serialization/4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
   embedding: /usr/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll
   embedding: /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll
   embedding: /usr/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll
   embedding: /usr/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
   embedding: /usr/lib/mono/gac/System.Security/4.0.0.0__b03f5f7f11d50a3a/System.Security.dll
   embedding: /usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll
   embedding: /usr/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll
   embedding: /usr/lib/mono/gac/System.Data.Linq/4.0.0.0__b77a5c561934e089/System.Data.Linq.dll
   embedding: /usr/lib/mono/gac/System.Data/4.0.0.0__b77a5c561934e089/System.Data.dll
   embedding: /usr/lib/mono/gac/Mono.Data.Tds/4.0.0.0__0738eb9f132ed756/Mono.Data.Tds.dll
   embedding: /usr/lib/mono/gac/System.Transactions/4.0.0.0__b77a5c561934e089/System.Transactions.dll
   embedding: /usr/lib/mono/gac/System.EnterpriseServices/4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
Compiling:
as -o temp.o temp.s 
cc -ggdb -o Agent -Wall temp.c `pkg-config --cflags --libs mono-2`  temp.o
Done

现在,让我们file再次运行命令,这次是针对生成的"Agent"二进制文件:

file Agent
Agent: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=698384c13208eccc609e5a573deeb09ed3420a29, not stripped
Run Code Online (Sandbox Code Playgroud)

注意:此本机二进制文件仍依赖于libmono(Mono运行时库),因此如果没有可用的Mono安装,它将无法在计算机上运行.

但是,您可以将libmono嵌入到二进制文件中,并使用mkbundle --static选项获取独立的,自包含的可执行文件.