Why is the default platform target for a WPF applications in Visual Studio x86 and not AnyCPU?

佐手、 提交于 2019-12-12 08:06:05

问题


When I create a new WPF application in Visual Studio 2012 the platform target and build configuration is set to x86 by default. Why is this the case? For a plain WPF application (without any references to mixed mode assemblies) is there any danger using AnyCPU so my WPF executable will be JITed to x64 code on my x64 machine and to x86 on a x86 machine?


回答1:


Why is this the case?

For most applications, building as 32bit is actually better. 64bit provides few benefits, and some significant disadvantages in most cases (much higher memory usage, more complex dependency management with multiple platforms, worse debugging experience, etc).

If, however, your application needs to be able to use large amounts of memory, then of course 64bit has advantages (and is easy to switch in VS), but most applications do not fall into this boat.

This is why the new default in VS 2012 is to use AnyCPUPrefer32Bit instead of AnyCPU for applications.




回答2:


According to this bug report, it was done because of problems with Edit and Continue on x64 machines with x64 code. By changing it to x86, Edit and Continue works properly.

There should be no danger in switching it to AnyCPU. I always do this.




回答3:


If you choose to specify a CPU, then you automatically limit your .exe to one platform or the other.

There is seldom any reason to do this, unless you absolutely have 32-bit dependencies:

  • What does the Visual Studio "Any CPU" target mean?

  • /CLRIMAGETYPE

In other words, there's no "performance" issue. The real issue is "compatibility". If you load any 32-bit components, and you're on a 64-bit platorm, then you must invoke WOW64. CLRTIMAGETYPE allows you to do that.



来源:https://stackoverflow.com/questions/11037329/why-is-the-default-platform-target-for-a-wpf-applications-in-visual-studio-x86-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!