Why has .NET-code to be compiled for multiple platforms

.net

Solution

You've just been doing it wrong. The IL is exactly the same, regardless of the platform selection.

When you create a new Phone project in Visual Studio 2013, you get a solution with three Platform selections: AnyCPU, x86 and ARM. The latter two are superfluous in a pure .NET project. The only reason that they are present is because Phone also supports native C++ projects. Where the target architecture does matter since C++ is compiled directly to machine code.

In a pure .NET project you only ever need AnyCPU. Named quite appropriately of course ;)

Problem

When e. g. creating a Windows Phone app, I have to select x86 for debugging in the emulator and ARM for debugging on the phone. Thats of course because my PC is running x86 (x64, to be specific, but x64 processors only differ in register length (please correct me if I'm wrong)) and my phone has got an ARM processor. But unlike C++ C# isn't compiled directly into assembler, but in some kind of intermediate langugage. So my question is: why does this intermediate language differ for different platforms. Wouldn't it be enough to rewrite the virtual machine interpreting the intermediate language? E. g. Java runs on Mac, PC etc. without having to compile for every platform.

Original source