What does the Visual Studio “Any CPU” target mean?

后端 未结 8 842
栀梦
栀梦 2020-11-22 05:05

I have some confusion related to the .NET platform build options in Visual Studio 2008.

What is the \"Any CPU\" compilation target, and what sort of files does it ge

相关标签:
8条回答
  • 2020-11-22 06:05

    I think most of the important stuff has been said, but I just thought I'd add one thing: If you compile as Any CPU and run on an x64 platform, then you won't be able to load 32-bit DLL files, because your application wasn't started in WoW64, but those DLL files need to run there.

    If you compile as x86, then the x64 system will run your application in WoW64, and you'll be able to load 32-bit DLL files.

    So I think you should choose "Any CPU" if your dependencies can run in either environment, but choose x86 if you have 32-bit dependencies. This article from Microsoft explains this a bit:

    /CLRIMAGETYPE (Specify Type of CLR Image)

    Incidentally, this other Microsoft documentation agrees that x86 is usually a more portable choice:

    Choosing x86 is generally the safest configuration for an app package since it will run on nearly every device. On some devices, an app package with the x86 configuration won't run, such as the Xbox or some IoT Core devices. However, for a PC, an x86 package is the safest choice and has the largest reach for device deployment. A substantial portion of Windows 10 devices continue to run the x86 version of Windows.

    0 讨论(0)
  • 2020-11-22 06:05

    Here's a quick overview that explains the different build targets.

    From my own experience, if you're looking to build a project that will run on both x86 and x64 platforms, and you don't have any specific x64 optimizations, I'd change the build to specifically say "x86."

    The reason for this is sometimes you can get some DLL files that collide or some code that winds up crashing WoW in the x64 environment. By specifically specifying x86, the x64 OS will treat the application as a pure x86 application and make sure everything runs smoothly.

    0 讨论(0)
提交回复
热议问题