How to compile a .NET application to native code?

RemoteSoft makes a tool that compiles a .NET application into a package that can be run without .NET installed. I don't have any experience with it:

RemoteSoft Salamander


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


As some of the other answers here have mentioned, you can use the .NET Native tool to compile your app to native machine code. Unlike those answers, however, I will explain how to do it.

Steps:

  1. Install the dotnet CLI (command line interface) tool, which is part of the new .NET Core toolchain. We'll use this to compile our app; you can find a good article about it here.

  2. Open up a shell prompt and cd to the directory of your app.

  3. Type this:

    dotnet compile --native
    

That's it! When you're done, your app will be compiled down to a single binary, like this:

Native compiled .NET Core EXE

It'll be a standalone executable; no PDBs, assemblies, or config files included (hooray!).


Alternatively, if you want an even faster program, you can run this:

dotnet compile --native --cpp

That will optimize your program using the C++ code generator (as opposed to RyuJIT), so your app is even more optimized for AOT scenarios.

You can find more info on this at the dotnet CLI GitHub repo.