为什么编译为 Any CPU 生成 x86 exe?

Why is compiling as Any CPU producing an x86 exe?

我正在尝试在发布模式下将 C# 程序编译为 Any CPU。由于 Any CPU 设置,我希望正在创建的 exe 是 MSIL processor architecture。但是,它输出的是 x86(我正在使用 dotPeek 程序集浏览器进行检查)。

如果我指定它是一个 x64 程序,我将得到一个 x64 程序。同样,当我指定 x86 时。

我应该得到一个 MSIL 处理器架构,因为 Any CPU 对吗?为什么没有发生?

您还需要取消选中 Prefer 32-bit

Properties -> Build -> Prefer 32-bit

这有点旧,但仍然适用

What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11

The difference, then, between “Any CPU 32-bit preferred” and “x86” is only this: a .NET application compiled to x86 will fail to run on an ARM Windows system, but an “Any CPU 32-bit preferred” application will run successfully.