Today, the code of the project received feedback from customers, requiring that all target platforms for EXE projects be designated as x86, and all target platforms for DLL projects be designated as AnyCPU.
Let ’s take a look at what this target platform does and what are the differences between the options.
In VisualStudio, there are the following options in the compilation settings:
x86: Compiles the assembly to run by an x86-compatible 32-bit common language runtime.
x64: Compiles the assembly to run by a 64-bit common language runtime on a computer that supports the AMD64 or EM64T instruction set.
anycpu: (default) compiles the assembly to run on any platform.
Itanium: Compiles the assembly to run by a 64-bit common language runtime on a computer with an Itanium processor.
The specific behavior is as follows:
On 64-bit Windows operating systems:
An assembly compiled with x86 will execute on a 32-bit CLR running under WOW64.
An assembly compiled with x64 will execute on a 64-bit CLR.
Executables compiled with anycpu will execute on the 64-bit CLR.
A DLL compiled with anycpu will execute on the same CLR as the process that loaded it.
On 32-bit Windows operating systems:
An assembly compiled with x86 or anycpu will execute on a 32-bit CLR.
An assembly compiled with x64 cannot run.
After you understand these differences, look back at what the customer asked for. Does it make sense?
First of all, I know that customers want the program to run on all systems above WINXP (whether it is 32-bit or 64-bit).
Therefore, it is impossible to choose x64, and Itanium will not choose it for special processors.
Is there any problem in choosing the default method of Any CPU?
First look at the difference between Any CPU and x86 executable files (EXE) in 32-bit and 64-bit,
If the Any CPU is 32-bit, the EXE will execute in 32-bit, and under 64-bit, the EXE will execute in 64-bit. For x86, it is always executed in 32 bits.
The customer wants to use x86, that is, does not want to execute the EXE program in 64-bit mode in 64-bit mode. The reason I analyzed is because there may be a third-party 32-bit DLL in the system. Once a 64-bit EXE is used, it cannot be called when calling a 32-bit DLL.
For DLL, customers want to use Any CPU. The reason I analyzed is that the actual operation mode of DLL is affected by the EXE that calls it, so it can be set to Any CPU. If it is set to x86, although it seems to be fine, it cannot run in the 64-bit CLR, which is not good.
------------------------------
In addition, you can use the CorFlags command provided in the .NET SDK to view the target platform of the assembly, or you can modify it so that you do not need to recompile. However, why can't a 64-bit EXE call a 32-bit DLL?
Personal original blog, please indicate the source address: https://www.cnblogs.com/xyyt
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.