如何将.NET exe转换为本地Win32 exe?

4

我该如何将.NET exe转换为Win32 exe?(我没有代码) 目的是使用wine在Linux中运行应用程序。 我认为不能在wine中运行.NET exe,而且我不想使用mono。

6个回答

3

我只有exe文件,没有使用NGen编译的代码。 - softwarematter
与此同时,我将尝试在Wine中运行.NET exe。 - softwarematter
NGen将IL编译为机器指令。它并不能神奇地将.NET依赖项转换为本机Win32依赖项,或将托管堆内存转换为非托管本机堆内存。您仍然需要CLR来运行NGen生成的模块。@devnull:您不需要源代码来运行NGen对模块进行编译,就像您不需要源代码来运行JIT编译器一样。 - IInspectable

2

我确认:我有一个相当大的应用程序,使用了几个第三方程序集和 P/invoke 调用,在 Wine + Mono 上运行良好。 - Thomas Levesque

2
这可能对您来说是一个困难的解决方案,但我在这里提到它是为了完整性的考虑。
据说您可以使用VMWare的Thinapp来包装一个.NET应用程序。我相信这将导致一个Win32可执行文件。

https://www.vmware.com/products/thinapp


1

使用静态库的预编译器。在Mono中也称为mkbundle。

Mono带有一个命令行界面,用于将AOT(提前)编译成JIT编译器。您可以使用此功能创建一个静态链接的.o文件,然后使用调用对象文件的mono运行时嵌入器的简单包装器来运行它。如果您随后静态链接到Mono库,则不会有任何外部依赖项安装.NET框架。

当然,您必须发送所有静态链接的库,否则最终会得到一个巨大的exe文件,但是这就是您要求的。

mono --aot=static

          static Create  an  ELF  object file (.o) which can be statically linked into an executable when embedding the mono runtime. When this option is used, the object
                 file needs to be registered with the embedded runtime using the mono_aot_register_module function which takes as its argument the mono_aot_module_<ASSEM‐
                 BLY NAME>_info global symbol from the object file:

                 extern void *mono_aot_module_hello_info;

                 mono_aot_register_module (mono_aot_module_hello_info);

虽然我在Linux上使用过这个,但我不完全确定它在Windows上同样有效。

更新:记得mkbundle工具:

sehe@sehelap:~$ mkbundle --static test.exe -o hello
OS is: Linux
Note that statically linking the LGPL Mono runtime has more licensing restrictions than dynamically linking.
See http://www.mono-project.com/Licensing for details on licensing.
Sources: 1 Auto-dependencies: False
   embedding: /home/sehe/test.exe
Compiling:
as -o temp.o temp.s 
cc -o hello -Wall `pkg-config --cflags mono` temp.c  `pkg-config --libs-only-L mono` -Wl,-Bstatic -lmono -Wl,-Bdynamic `pkg-config --libs-only-l mono | sed -e "s/\-lmono //"` temp.o
Done
sehe@sehelap:~$ ./hello 
hello world

sehe@sehelap:~$ ldd hello 
linux-gate.so.1 =>  (0xb7875000)
libdl.so.2 => /lib/libdl.so.2 (0xb785f000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb7845000)
libm.so.6 => /lib/libm.so.6 (0xb781e000)
libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0 (0xb7819000)
librt.so.1 => /lib/librt.so.1 (0xb7810000)
libglib-2.0.so.0 => /lib/libglib-2.0.so.0 (0xb7741000)
libc.so.6 => /lib/libc.so.6 (0xb75e4000)
/lib/ld-linux.so.2 (0xb7876000)
libpcre.so.3 => /lib/libpcre.so.3 (0xb75af000)

啊,我刚想起来直接使用 mkbundle mkbundle --static test.exe -o test 可能比手动编译嵌入包装器更容易 :) - sehe

1

也许可以在Mono下运行?


这是一个WinForm账户管理应用程序,根据输入处理Excel文件。 - softwarematter
1
好的,那么我猜想在mono下运行它会比较棘手(因为它依赖于Excel)。 - Fredrik Mörk

0

这是不可能的。对于托管代码,您需要某种VM来运行。在Linux中,您可以使用Mono或dotgnu portable.net。也许某个超级先进版本的Wine将能够运行MS .net框架?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接