为 Visual Studio 应用程序设置平台目标的目的是什么? [英] What is the purpose of setting the platform target for a Visual Studio application?

查看:29
本文介绍了为 Visual Studio 应用程序设置平台目标的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于任何 VS 项目,都可以在该项目的构建属性中设置平台目标.您可以将其设置为 Any CPU、x86、x64 或 Itanium.我的问题是,如果我将此值设置为 x86,是否意味着我无法在 x64 机器上运行该项目?如果是这样,为什么甚至使用它?总是使用 Any CPU 不是更好吗?

For any VS project it is possible to set the platform target in the build properties of that project. You can set this to Any CPU, x86, x64 or Itanium. My question is, if I set this value to x86 does that mean I cannot run that project on a x64 machine? If so, why is this even used? Is it not better to just always use Any CPU?

推荐答案

如果我将此值设置为 x86 是否意味着我无法在 x64 机器上运行该项目?

if I set this value to x86 does that mean I cannot run that project on a x64 machine?

不,32 位应用程序 (x86) 在 64 位 Windows (x64) 上运行得很好.所有 64 位版本的 Windows 都包含一个 32 位兼容层,称为 Windows 64 上的 Windows (WOW64).这通常正是您想要的,事实上,因为大多数应用程序都无法从 64 位编译中受益.

No, 32-bit applications (x86) run just fine on 64-bit Windows (x64). All 64-bit versions of Windows include a 32-bit compatibility layer called Windows on Windows 64 (WOW64). This is usually what you want, in fact, as most applications do not benefit from being complied for 64-bit.

但是,针对 64 位 (x64) 进行编译确实意味着您的应用无法在 32 位 (x86) 机器上运行.您可以倒退(64 位可以运行 32 位),但不能前进(32 位不能运行 64 位).

However, compiling for 64-bit (x64) does mean that your app will not run on a 32-bit (x86) machine. You can go backwards (64-bit can run 32-bit), but you cannot go forwards (32-bit cannot run 64-bit).

Any CPU 编译始终是一个选项,正如您所指出的.这将允许应用程序在 32 位机器上作为 32 位应用程序 (x86) 运行,并在 64 位机器上作为 64 位应用程序 (x64) 运行.这听起来像是灵丹妙药,但需要付出代价.最值得注意的是,您需要在 32 位和 64 位环境中广泛测试您的应用程序,而如果您只针对 32 位环境(包括 64 位环境中的 32 位环境)主机),您只需要测试一个构建.而且额外的工作负载很少值得——大多数业务应用程序并没有从 64 位环境的额外内存空间中受益,并且最终可能会因 64 位指针的开销增加而失去任何潜在的收益.

Compiling for Any CPU is always an option, as you point out. That will allow the application to run as a 32-bit application (x86) on a 32-bit machine, and as a 64-bit application (x64) on a 64-bit machine. This sounds like a panacea, but there are costs. Most notably, you'll need to test your application extensively in both 32-bit and 64-bit environments, whereas if you only target 32-bit environments (including 32-bit environments on a 64-bit host), you only have to test one build. And the additional workload is rarely worth it—most business applications do not benefit from the extra memory space of a 64-bit environment, and probably end up defeating any potential gains by the increased overhead of 64-bit pointers.

Visual Studio 本身就是完全 32 位应用程序的一个很好的例子.没有 64 位版本,但它在 64 位主机上运行良好.此博客帖子 有助于阐明为什么决定保留 VS 32 位.您可能会发现推理有助于自己做出决定.

Visual Studio itself is a good example of an application that is fully 32-bit. There is no 64-bit version, yet it runs fine on a 64-bit host. This blog post helps to shed some light on why the decision has been made to keep VS 32-bit. You might find the reasoning helpful in making the decision yourself.

同样,尽管 Microsoft Office 现在提供 64 位软件包,但 Microsoft 仍然建议大多数客户坚持使用 32 位版本.64 位版本存在兼容性问题,没有太多好处.

Likewise, although Microsoft Office is now available in a 64-bit package, Microsoft is still recommending that most customers stick with the 32-bit version. There are compatibility problems with the 64-bit version, and there just isn't much benefit.

这篇关于为 Visual Studio 应用程序设置平台目标的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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