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

后端 未结 8 849
栀梦
栀梦 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 05:41

    I recommend reading this post.

    When using AnyCPU, the semantics are the following:

    • If the process runs on a 32-bit Windows system, it runs as a 32-bit process. CIL is compiled to x86 machine code.
    • If the process runs on a 64-bit Windows system, it runs as a 32-bit process. CIL is compiled to x86 machine code.
    • If the process runs on an ARM Windows system, it runs as a 32-bit process. CIL is compiled to ARM machine code.
    0 讨论(0)
  • 2020-11-22 05:43

    Credit to the book "CLR via C#", see this:

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

    An AnyCPU assembly will JIT to 64-bit code when loaded into a 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.

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

    Any CPU means that it will work on any platform. This is because managed code is similar to Java. Think of it as being compiled to a byte code that is interpreted by the .NET Framework at run-time.

    C++ does not have this option because it is compiled to machine code that is platform specific.

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

    Check out the article Visual Studio .NET Platform Target Explained.

    The default setting, "Any CPU", means that the assembly will run natively on the CPU it is currently running on. Meaning, it will run as 64-bit on a 64-bit machine and 32-bit on a 32-bit machine. If the assembly is called from a 64-bit application, it will perform as a 64-bit assembly and so on.

    The above link has been reported to be broken, so here is another article with a similar explanation: What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11

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

    "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.

    dumpbin YourProgram.exe /headers
    

    It will tell you the bitness of your program, plus a whole lot more.

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