. NET program before compiling, modifying the target platform only affects the compiled assembly. And the effect on the assembly is exactly where it is, so to speak.
There are several parts in the generated assembly, which are part of the assembly and, of course, a part of the disk space in the final analysis. There are MS-DOS placeholder program, COFF head, PE head and so on (of course, also contains a lot, specifically can check the relevant information). The first field of a PE header identifies the Magic field. That is, the target platform properties that were modified prior to compilation cause the corresponding fields of the generated assembly to change. This change is reflected in the difference in run time.
Running an executable file, Windows checks the header of the executable, determines whether it is a PE32 header or pe32+ header, PE32 head can run on x86, Itanium, and x64 architectures, and pe32+ can only run on a x64 or Itanium-architected machine.
The specific explanation is:
If the target platform is set to AnyCPU before compiling, then PE32 is generated, and the JIT compiler at run time can generate the IL code as the corresponding machine code based on the current machine.
If the target platform is set to x86 before compiling, then PE32 is generated, if run on x86 machine, the JIT compiler can generate the IL code corresponding machine code, if on the x64 or Itanium machine, Microsoft provides a technology called WOW64 (Windows on WINDOWS64), then the Mscoree.dll under C:\Windows\SysWoW64 is run, forcing the x86 assembly to be simulated
If the target platform is set to x64 before compiling, pe32+ is generated and will not work on both the x86 and Itanium machines.
If the target platform is set to Itanium before compiling, pe32+ is generated and cannot be run on both the x86 and x64 machines.
The specific correspondence is as follows:
Target platform |
Built-in managed modules |
X86windows |
X64windows |
Itanium |
AnyCPU |
PE32 |
Run as a 32-bit program |
Run as a 64-bit program |
Run as a 64-bit program |
X86 |
PE32 |
Run as a 32-bit program |
Run as WOW64 application |
Run as WOW64 application |
X64 |
pe32+ |
Do not run |
Run as a 64-bit program |
Do not run |
Itanium |
pe32+ |
Do not run |
Do not run |
Run as a 64-bit program |
The impact of target platform options on the generated modules and runtimes