visual-studio 是否可以将 .NET IL 代码编译为机器代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/140750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to compile .NET IL code to machine code?
提问by litter
I would like to distribute my .NET programs without the .NET framework. Is it possible to compile a .NET program to machine code?
我想在没有 .NET 框架的情况下分发我的 .NET 程序。是否可以将 .NET 程序编译为机器代码?
采纳答案by FlySwat
Yes, you can precompile using Ngen.exe, however this does not remove the CLR dependence.
是的,您可以使用 Ngen.exe 进行预编译,但这不会消除 CLR 依赖。
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.
您仍然必须提供 IL 程序集,Ngen 的唯一好处是您的应用程序可以在不调用 JIT 的情况下启动,因此您可以获得真正快速的启动时间。
According to CLR Via C#:
根据 CLR Via C#:
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.
此外,使用 Ngen 预编译的程序集通常比 JIT 编译的程序集慢,因为 JIT 编译器可以针对目标机器(32 位?64 位?特殊寄存器?等)进行优化,而 NGEN 只会生成基线编译。
EDIT:
编辑:
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.
关于 CLR Via C# 的上述信息存在一些争论,因为有人说您只需要在目标机器上运行 Ngen 作为安装过程的一部分。
回答by OregonGhost
Remotesoft has one: Salamander .NET Linker
Remotesoft 有一个: Salamander .NET Linker
I don't have any experience with it though.
虽然我没有任何经验。
回答by Turnkey
There are some third party tools that do this, e.g.
有一些第三方工具可以做到这一点,例如
回答by Jacob
Another (expensive and proprietary, licenses start at $1599) product that can do this is Xenocode Postbuild. Haven't used it myself though, with it costing about the gross national product of a small African country and all...
另一种(昂贵且专有,许可证起价为 1599 美元)可以做到这一点的产品是Xenocode Postbuild。不过我自己没用过,它的成本大约是一个非洲小国的国民生产总值和所有......
回答by C. Dragon 76
Is it possible to compile .NET IL code to machine code?
是否可以将 .NET IL 代码编译为机器代码?
Yes, but the .NET Framework does it for you at runtime (default) or at install time (ngen). Among other reasons, this IL -> machine code is done separately on each install machine so it can be optimized for that particular machine.
是的,但 .NET Framework 会在运行时(默认)或安装时 (ngen) 为您执行此操作。除其他原因外,此 IL -> 机器代码在每台安装机器上单独完成,因此可以针对该特定机器进行优化。
I would like to distribute my .NET programs without the .NET framework. Is it possible to compile a .NET program to machine code?
我想在没有 .NET 框架的情况下分发我的 .NET 程序。是否可以将 .NET 程序编译为机器代码?
No, for all intents and purposes you cannot do this. The 3rd party workarounds may work in some scenarios, but by then I wouldn't really consider it "managed code" or ".NET" anymore.
不,出于所有意图和目的,您不能这样做。第 3 方变通方法可能在某些情况下有效,但到那时我不会真正将其视为“托管代码”或“.NET”。
回答by Stan Prokop
Yes, you can now! Recently Microsoft announced .NET Native, a piece of technology that compiles your application with .NET Native runtime (they call it MRT) into one binary (actually one executable and one dynamic library).
是的,你现在可以!最近,Microsoft 宣布了.NET Native,这是一项技术,可将带有 .NET Native 运行时(他们称之为 MRT)的应用程序编译成一个二进制文件(实际上是一个可执行文件和一个动态库)。
See links: http://blogs.msdn.com/b/dotnet/archive/2014/04/02/announcing-net-native-preview.aspxhttp://blogs.msdn.com/b/dotnet/archive/2014/04/24/dotnetnative-performance.aspx
查看链接:http: //blogs.msdn.com/b/dotnet/archive/2014/04/02/announcing-net-native-preview.aspx http://blogs.msdn.com/b/dotnet/archive/ 2014/04/24/dotnetnative-performance.aspx
回答by LicenseQ
Look at MONO project: mono command with --aot option. http://www.mono-project.com/AOT
查看 MONO 项目:带有 --aot 选项的 mono 命令。http://www.mono-project.com/AOT
回答by CodeChef
回答by Pablo Marambio
I think you should not: That's the task of the JIT compiler.
我认为你不应该:这是 JIT 编译器的任务。
However, you could use ClickOnce or Windows Installer to deploy it so that the missing framework isn't such a big problem: you could tell the installer to download the Framework and install it.
但是,您可以使用 ClickOnce 或 Windows Installer 来部署它,这样缺少的框架就不是什么大问题:您可以告诉安装程序下载该框架并安装它。

