Just wondering if a .NET app can be compiled down to native machine code ahead of time? I'm not planning on doing so even if I could; I'm just curious.
只是想知道.NET应用程序是否可以提前编译为本机代码?即使我可以,我也不打算这样做;我只是好奇。
Thanks
4 个解决方案
#1
11
You can use NGen to compile it ahead of time, but this still depends on the .NET framework. Remotesoft's Salamander (a commercial app) can make a framework-less app.
您可以使用NGen提前编译它,但这仍然取决于.NET框架。 Remotesoft的Salamander(一个商业应用程序)可以制作一个无框架的应用程序。
#2
5
You CAN compile IL into native binaries. There are products that do it.
您可以将IL编译为本机二进制文件。有产品可以做到这一点。
The larger question is should you...
更大的问题是你应该......
If you want to remove all dot net dependencies to run without dot net
如果要删除所有点网依赖关系以在没有点网的情况下运行
Basically what these products are doing is precompiling down to the machine level (x86 usually) and then statically including all the required libraries in your exe. That usually results in a HUGE exe. And, more importantly, you now don't really have the runtime on your target machine. You have a part of the runtime that the native compiler chose to incorporate.
基本上这些产品正在做的是预编译到机器级别(通常是x86),然后静态地包含exe中所有必需的库。这通常导致巨大的exe。而且,更重要的是,您现在并没有真正拥有目标计算机上的运行时。您拥有本机编译器选择合并的运行时的一部分。
If you want to just get a faster JIT time
如果你想获得更快的JIT时间
You can also use NGen to compile it to a native binary, but you still have all the dependencies on dot net. Target machines still need the framework, etc.
您也可以使用NGen将其编译为本机二进制文件,但您仍然拥有dot net的所有依赖项。目标机器仍然需要框架等。
But, when you ngen you LOSE the ability for the app to auto promote up to 64 bit. If your app is precompiled you have to force one mode. If a user is running on a 64 bit machine your IL code would have promoted (unless you flag it not to).
但是,当你发现你失去了应用程序自动提升高达64位的能力。如果您的应用程序已预编译,则必须强制使用一种模式。如果用户在64位计算机上运行,则IL代码将被提升(除非您将其标记为不)。
The JIT time is not your biggest bottleneck in most apps. It is the loading of the framework libraries and other related requirements.
JIT时间不是大多数应用程序中最大的瓶颈。它是框架库的加载和其他相关要求。
If you really need it you can ngen within a setup app to get the current users target machine.
如果您真的需要它,您可以在安装应用程序中获取当前用户目标计算机。
I also just recently learned that you cannot NGEN an app and expect it to take advantage of the CPU like you can with the JIT. When you run NGEN is always optimizes the output for a PentiumPro for some reason, and will not take advantage of things like SSE, SSE2, etc. So I would say that removes NGEN as a reasonable usage case.
我最近才知道你不能NGEN一个应用程序,并期望它像你可以使用JIT一样利用CPU。当你运行NGEN时总是出于某种原因优化PentiumPro的输出,并且不会利用SSE,SSE2等等。所以我会说取消NGEN是一个合理的用例。
#3
1
ngen can be used to 'pre-JIT' an image, so it is available on disk in native form to reduce application start up time.
ngen可以用于“预JIT”图像,因此它可以在磁盘上以原生形式提供,以减少应用程序启动时间。
#4
1
Mono has an Ahead of Time (AOT) compiler that can emit native code.
Mono有一个可以发出本机代码的Ahead of Time(AOT)编译器。
#1
11
You can use NGen to compile it ahead of time, but this still depends on the .NET framework. Remotesoft's Salamander (a commercial app) can make a framework-less app.
您可以使用NGen提前编译它,但这仍然取决于.NET框架。 Remotesoft的Salamander(一个商业应用程序)可以制作一个无框架的应用程序。
#2
5
You CAN compile IL into native binaries. There are products that do it.
您可以将IL编译为本机二进制文件。有产品可以做到这一点。
The larger question is should you...
更大的问题是你应该......
If you want to remove all dot net dependencies to run without dot net
如果要删除所有点网依赖关系以在没有点网的情况下运行
Basically what these products are doing is precompiling down to the machine level (x86 usually) and then statically including all the required libraries in your exe. That usually results in a HUGE exe. And, more importantly, you now don't really have the runtime on your target machine. You have a part of the runtime that the native compiler chose to incorporate.
基本上这些产品正在做的是预编译到机器级别(通常是x86),然后静态地包含exe中所有必需的库。这通常导致巨大的exe。而且,更重要的是,您现在并没有真正拥有目标计算机上的运行时。您拥有本机编译器选择合并的运行时的一部分。
If you want to just get a faster JIT time
如果你想获得更快的JIT时间
You can also use NGen to compile it to a native binary, but you still have all the dependencies on dot net. Target machines still need the framework, etc.
您也可以使用NGen将其编译为本机二进制文件,但您仍然拥有dot net的所有依赖项。目标机器仍然需要框架等。
But, when you ngen you LOSE the ability for the app to auto promote up to 64 bit. If your app is precompiled you have to force one mode. If a user is running on a 64 bit machine your IL code would have promoted (unless you flag it not to).
但是,当你发现你失去了应用程序自动提升高达64位的能力。如果您的应用程序已预编译,则必须强制使用一种模式。如果用户在64位计算机上运行,则IL代码将被提升(除非您将其标记为不)。
The JIT time is not your biggest bottleneck in most apps. It is the loading of the framework libraries and other related requirements.
JIT时间不是大多数应用程序中最大的瓶颈。它是框架库的加载和其他相关要求。
If you really need it you can ngen within a setup app to get the current users target machine.
如果您真的需要它,您可以在安装应用程序中获取当前用户目标计算机。
I also just recently learned that you cannot NGEN an app and expect it to take advantage of the CPU like you can with the JIT. When you run NGEN is always optimizes the output for a PentiumPro for some reason, and will not take advantage of things like SSE, SSE2, etc. So I would say that removes NGEN as a reasonable usage case.
我最近才知道你不能NGEN一个应用程序,并期望它像你可以使用JIT一样利用CPU。当你运行NGEN时总是出于某种原因优化PentiumPro的输出,并且不会利用SSE,SSE2等等。所以我会说取消NGEN是一个合理的用例。
#3
1
ngen can be used to 'pre-JIT' an image, so it is available on disk in native form to reduce application start up time.
ngen可以用于“预JIT”图像,因此它可以在磁盘上以原生形式提供,以减少应用程序启动时间。
#4
1
Mono has an Ahead of Time (AOT) compiler that can emit native code.
Mono有一个可以发出本机代码的Ahead of Time(AOT)编译器。