Search code examples
c#visual-studioxamarinbuildanycpu

Is it advised to choose always the target AnyCPU for Xamarin projects?


When trying other target other than AnyCPU, I get more errors and the dependencies are more tricky to resolve.

But when choosing AnyCPU target, I get less errors.

Is it advised to choose always this target for Xamarin projects?


Solution

  • Let's clarify.

    Xamarin project is a very generic term and thus means nothing specific. In order to get friendly with the "platform" factor you will have to look at all three platforms separately.

    First of all, keep in mind that your C# source code is compiled into IL (Intermediate Language) by Microsoft .NET compiler (Roslyn for instance). Platform specification is not yet used. At that moment it is just metadata. Later the code is compiled from IL to platform specific code . That is when platform specification is really used.

    1. Microsoft Windows (here I mean Windows 8.1/Windows Phone 8.1 (WinRT universal app) and Windows 10/Windows Phone 10 (UWP)). Use AnyCPU for all the projects. Under the hood, when you build your packages for distribution, specific platform other than AnyCPU will be picked for Phone packages. You do not have to worry about that.

    2. Google Android. Things get a little bit tricky there. All the class libraries you make can be configured for AnyCPU as well as the Startup project but this has nothing to do with the actual platform specific compilation and linking. This becomes a mere configuration group in terms of the Visual Studio metadata and nothing else. Real configuration is on a separate tab in startup project configuration page Android options -> Advanced. At the moment I write this the actual choice is armeabi-v7a + x86.

    3. Apple iOS. Now it is tricky and even weird. All the class libraries you use can be configured for AnyCPU but this is just a configuration group as well as for android. Again, and this is the same with android, actual compilation and linking will be made using platform specific configuration from the startup project properties. Now it is iOS Build -> Advanced. At the moment I am using ARMv7 + ARM64 for distribution (iPhone platform option) and i386 + x86_64 for development (iPhoneSimulator platform option).