4

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 and I don't want to use mono.

softwarematter
  • 28,015
  • 64
  • 169
  • 263

6 Answers6

3

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.

blacktau
  • 169
  • 1
  • 4
  • All I have is the exe. I don't have the code to compile using NGen. – softwarematter May 11 '09 at 06:56
  • Meanwhile I'll try out running the .NET exe in wine. – softwarematter May 11 '09 at 07:03
  • NGen compiles IL to machine instructions. It doesn't miraculously turn the .NET dependencies into native Win32 dependencies, or managed heap memory into unmanaged native heap memory. You still need the CLR to run an NGen'ed module. @devnull: You don't need source code to run NGen against a module, much like you don't need source code to run the JIT compiler. – IInspectable Oct 19 '16 at 20:05
2

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

NullUserException
  • 83,810
  • 28
  • 209
  • 234
Fredrik Leijon
  • 2,792
  • 18
  • 20
  • I confirm that : I have a pretty big application using several third-party assemblies and P/invoke calls, and it works fine with Wine + Mono – Thomas Levesque May 11 '09 at 09:52
2

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

MathuSum Mut
  • 2,765
  • 3
  • 27
  • 59
Unknown
  • 45,913
  • 27
  • 138
  • 182
1

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)
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Ah, I just remembered that is probably easier to use `mkbundle mkbundle --static test.exe -o test` directly instead of having to manually compile up the embedding wrapper :) – sehe Mar 30 '11 at 10:00
1

Perhaps it will run under mono?

Fredrik Mörk
  • 155,851
  • 29
  • 291
  • 343
0

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?

Erich Kitzmueller
  • 36,381
  • 5
  • 80
  • 102