问题描述
我想在没有 .NET 框架的情况下分发我的 .NET 程序.是否可以将 .NET 程序编译为机器码?
I would like to distribute my .NET programs without the .NET framework. Is it possible to compile a .NET program to machine code?
推荐答案
是的,你可以使用 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.
这篇关于是否可以将 .NET IL 代码编译为机器代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!