How to convert a .NET exe to native Win32 exe?

后端 未结 6 2120
广开言路
广开言路 2020-12-18 09:45

How can I convert a .NET exe to Win32 exe? (I don\'t have the code) The purpose is to run the application in Linux using wine. I presume that .NET exe cannot be run in wine

相关标签:
6条回答
  • 2020-12-18 09:53

    Depending on your framework version it might work with Wine .Net Framework compability in Wine

    0 讨论(0)
  • 2020-12-18 09:54

    depending on what version of .NET it is and what libraries it makes use of you could try running it under Mono without compiling the IL down to native code.

    most Linux distributions have it available under their package management systems.

    see: http://www.mono-project.com/Main_Page for more details

    the alternative is to use NGen to do the compiling (http://blogs.msdn.com/clrcodegeneration/archive/2007/09/15/to-ngen-or-not-to-ngen.aspx). but i'm not sure that would work under WINE.

    0 讨论(0)
  • 2020-12-18 09:55

    Perhaps it will run under mono?

    0 讨论(0)
  • 2020-12-18 10:05

    Simply not possible. For managed code, you need some kind of VM to run in. In Linux you can use Mono or dotgnu portable.net. Maybe some hyper-advanced version of wine will once be able to run the MS .net framework?

    0 讨论(0)
  • 2020-12-18 10:15

    This is probably a difficult solution for you, but I mention it here in the interest of completeness.

    You can supposedly wrap a .net application with VMWare's Thinapp. I believe this results in a win32 executable.

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

    0 讨论(0)
  • 2020-12-18 10:15

    Use the ahead-of-time compiler with static libraries. A.k.a. mkbundle on mono

    Mono comes with a commandline interface to the mono JIT compiler to compile AOT (ahead of time). You can use this to create a statically linked .o that you can then run with a trivial wrapper that invokes the mono runtime embedder with the object file. If you then statically link to the mono libraries, you won't have any external dependencies to an installed .NET framework.

    Of course, you will have to ship all the statically linked libraries or end up with a hughe exe but hey, it's what you asked for

    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);
    

    While I used this on linux, I'm not completely sure it works on windows equally well.

    Update Remembered the mkbundle tool:

    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)
    
    0 讨论(0)
提交回复
热议问题