Search code examples
.netcompilationnative-code

How to 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's no feature that I know of with the MS .Net framework SDK that allows you to compile all the required files into a single executable