x64 系统上的 x86 应用程序使用哪个 ngen?

Which ngen to use for x86 app on x64 system?

我决定问这个问题,因为没有找到明确的答案。我的 WPF 程序是 x86 (.Net 4.5.2)。我使用 Inno Setup 来安装和创建 ngen 映像。我应该在 64 位系统上安装时使用 Microsoft.NET\Framework64\v4.0.30319\ngen.exe,在 32 位系统上安装时使用 Microsoft.NET\Framework\v4.0.30319\ngen.exe 还是因为该程序是 x86 我应该一直使用 Microsoft.NET\Framework\v4.0.30319\ngen.exe?

这很容易,只需通过命令行 运行 ngen.exe 自己尝试即可。混合无法工作是crystal 清楚的,非常 对此喋喋不休。我将输出编辑为核心消息:

1>Ngen failed to generate native code for image C:\projects2\ConsoleApplication491\bin\Debug\ConsoleApplication491.exe because of the following error: The image file is not compatible with the version of Ngen you're running. Use 32bit Ngen for 32bit assemblies, and 64bit Ngen for 64bit assemblies. (Exception from HRESULT: 0x80131F07)

使用一个针对 x86 和 运行 ngen.exe 的 64 位版本的小测试项目生成。

x86(32 位应用程序)可以在 32 位和 64 位 Windows 机器上 运行。

x64 只能在 64 位 Windows 机器上 运行。

因此,如果您在 Visual Studio 中编译时将应用程序定位为 x86 应用程序,则应在 32 位和 64 位 Windows 上都使用 32 位 ngen机器。