构建平台目标 AnyCPU EXE 在 64 位机器中仍然显示 32 位标头 [英] Build platform target AnyCPU EXE still shows 32bit header in 64bit machine

查看:24
本文介绍了构建平台目标 AnyCPU EXE 在 64 位机器中仍然显示 32 位标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定之前是否有人问过这个问题(我找不到任何).我有简单的控制台应用程序/ESE 并具有以下设置.

Not sure this has been asked before (I could not find any). I have simple console app/ESE and have the below settings.

我运行的是 Windows 8 63 位操作系统.和 EXE 目标框架 .NET 4.5但是,当我编译这个 EXE 时,它仍然显示为 32 位 EXE.

I'm running Windows 8, 63bit OS. And the EXE target framework .NET 4.5 However, when I compile this EXE, it still shows as a 32bit EXE.

由于这是任何 CPU",我希望 EXE 编译为 64 位/PE32+.

Since this is "Any CPU", I would expect the EXE to compile as 64bit / PE32+.

有人可以帮忙解释为什么这仍然是 32 位吗?

Can some please help tell why this would be still 32bit?

推荐答案

我认为您误解了 CorFlags.这是一个 CorFlags 真值表:

You are misinterpreting CorFlags I think. Here is a CorFlags truth table:

CPU Architecture           PE      32BITREQ   32BITPREF
------------------------   -----   --------   ---------
x86 (32-bit)               PE32           1           0
x64 (64-bit)               PE32+          0           0
Any CPU                    PE32           0           0
Any CPU 32-Bit Preferred   PE32           0           1

如您所见,如果您将其编译为 64 位而不是 Any CPU,它只会报告 PE32+.原因是因为标头必须向后兼容.这意味着如果程序集要在 32 位和 64 位的任何 CPU"中工作,则标头格式必须采用 32 位操作系统可识别的格式.PE32+ 是仅 64 位的头格式,如果将该头应用于编译为 Any CPU 的程序集,那么 32 位操作系统将无法识别 PE32+ 标头格式.

As you can see, it will only report PE32+ if you compile it as 64-bit and not as Any CPU. The reason is because the header must be backward compatible. meaning if an assembly is to work in 'Any CPU', both 32 and 64 bit, then the header format must be in a format recognizable by a 32-bit operating system. PE32+ is a 64-bit only header format and if that header was applied to an assembly compiled as Any CPU, then a 32-bit operating system would not recognize the PE32+ header format.

这篇关于构建平台目标 AnyCPU EXE 在 64 位机器中仍然显示 32 位标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆