Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 887
Niyaz Avatar asked Sep 05 '08 12:09

Niyaz


People also ask

Can you compile C# to native code?

It automatically compiles the release version of apps that are written in managed code (C# or Visual Basic) and that target the . NET Framework and Windows 10 to native code. Your apps will provide the superior performance of native code. You can continue to program in C# or Visual Basic.

How a .NET application is compiled and executed?

NET application Source Code gets compiled into Microsoft Intermediate language (MSIL) which is also called Intermediate language (IL) or Common Intermediate language (CIL) code. Both . NET and Non-DOTNET applications generate an assembly when we compile the application. Generally, the assemblies have an extension of.

Is .NET native code?

NET Native is a precompilation technology for building and deploying UWP apps. . NET Native is included with Visual Studio 2015 and later versions. It automatically compiles the release version of UWP apps that are written in managed code (C# or Visual Basic) to native code.


1 Answers

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

like image 122
Espo Avatar answered Oct 06 '22 12:10

Espo