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.
Credit to book "CLR via C#", see this:
https://books.google.co.uk/books?id=36tCAwAAQBAJ&pg=PT38
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 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.
I recommend reading this post.
When using AnyCPU, the semantics are the following:
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)
Incidentally, this other Microsoft documentation agrees that x86 is usually a more portable choice:
"Any CPU" means that when the program is started, the .NET Framework will figure out, based on the OS bitness, whether to run your program in 32 bits or 64 bits.
There is a difference between x86 and Any CPU: on a x64 system, your executable compiled for X86 will run as a 32-bit executable.
As far as your suspicions go, just go to the Visual Studio 2008 command line and run the following.
It will tell you the bitness of your program, plus a whole lot more.