且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以将 .NET IL 代码编译为机器代码?

更新时间:2023-11-10 17:00:34

是的,你可以使用 Ngen.exe 进行预编译,但这并不能消除 CLR 依赖.

Yes, you can precompile using Ngen.exe, however this does not remove the CLR dependence.

您还必须提供 IL 程序集,Ngen 的唯一好处是您的应用程序可以在不调用 JIT 的情况下启动,因此您可以获得真正的快速启动时间.

You must still ship the IL assemblies as well, the only benefit of Ngen is that your application can start without invoking the JIT, so you get a real fast startup time.

根据 CLR 通过 C#:

According to CLR Via C#:

此外,使用预编译的程序集Ngen 通常比 JIT 慢程序集,因为 JIT 编译器可以针对目标机器进行优化(32 位?64 位?特殊寄存器?等),而 NGEN 只会产生一个基线编译.

Also, assemblies precompiled using Ngen are usually slower than JIT'ed assemblies because the JIT compiler can optimize to the targets machine (32-bit? 64-bit? Special registers? etc), while NGEN will just produce a baseline compilation.

对于来自 CLR Via C# 的上述信息存在一些争议,因为有人说您只需要在目标机器上运行 Ngen 作为安装过程的一部分.

There is some debate on the above info from CLR Via C#, as some say that you are required to run Ngen on the target machine only as part of the install process.