.netcompilationnative-code

How can I compile a .NET application to native code?


Let's say I want to run a .NET application on a machine where the .NET framework is not available; is there any way to compile the application to native code?


Solution

  • Microsoft has an article describing how you can Compile MSIL to Native Code

    You can use Ngen.

    The Native Image Generator (Ngen.exe) is a tool that improves the performance of managed applications. Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead using the just-in-time (JIT) compiler to compile the original assembly.

    Unfortunately, you still need the libraries from the framework in order to run your program. There isn't any feature that I know of with the Microsoft .NET framework SDK that allows you to compile all the required files into a single executable.