What does the Visual Studio "Any CPU" target mean?
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 generate? I examined the output executable of this "Any CPU" build and found that they are the x86 executables (who would not see that coming!). So, is there any the difference between targeting executable to x86 vs "Any CPU"?
Another thing that I noticed, is that managed C++ projects do not have this platform as an option. Why is that? Does that mean that my suspicion about "Any CPU" executables being plain 32-bit ones is right?
An AnyCPU assembly will JIT to 64 bit code when loaded into 64 bit process and 32 bit when loaded into a 32 bit process.
By limiting the CPU you would be saying : There is something being used by the assembly (something likely unmanaged) that requires 32 bits or 64 bits.
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 dlls, because your app wasn't started in WOW64, but those dlls need to run there.
If you compile as x86, then the x64 system will run you app in WOW64, and you'll be able to load 32-bit dlls.
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)
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 applications, 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 DLLs that collide or some code that winds up crashing WOW in the x64 environment. By specifically specifying x86, the x64 OS will treat the app as a pure x86 app and make sure everything runs smoothly.
链接地址: http://www.djcxy.com/p/13056.html上一篇: 空传播操作符和foreach