Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C# need the .NET framework to run if we use NGen.exe to compile it to native code?

Tags:

c++

c#

.net

I know C++ code runs on local machine directly. I also know that we can compile c# code into native code using NGen.exe. My question is

If we use Native code generator NGen.exe to compile c# code into native code, do we still need the .NET framework to run it?

like image 747
user1762254 Avatar asked Oct 20 '12 22:10

user1762254


1 Answers

In fact, if you compile your C++ code into a Windows executable you still need Win32 dlls and other stuffs. Your program cannot run on a CPU that does not have anything besides your program.

The same story for C#. If you compile C# to native code, you do not need the JIT compiler, that is part of .NET runtime. But you still need all other parts of .NET runtime.

For example, the .NET framework with all its classes is not linked into your program. If they would put all required .NET classes into your binary, a simple Hello world app would become huge.

like image 156
Kirill Kobelev Avatar answered Oct 31 '22 01:10

Kirill Kobelev