How to compile a .NET application to native code?

Niyaz picture Niyaz · Sep 5, 2008 · Viewed 56k times · Source

If I want to run a .NET application in a machine where the .NET framework is not available; Is there any way to compile the application to native code?

Answer

Espo picture Espo · Sep 5, 2008

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