Search code examples
performancexamarinoptimizationcompilationaot

Enabling Ahead of time compilation for Xamarin project


I have a xamarin application which is very slow, I need to improve this performance, with a little research I came across this concept of Ahead of time compilation. But I am not sure how to enable it for my project.

<AotAssemblies>True</AotAssemblies>

Apparently, I need to set this property to true in my .csproj file But I can't seem to find the file. Any help would be appreciated Plus this is my first question on StackOverflow so I hope to find some help.


Solution

  • This property need to be setted in native .csproj, but there is a easy way to set that with GUI of Visual stuido.

    For example, if want to set for Android in Visual Studio for PC, packaging properties can be set in the Android Options section of project Properties, as shown in the following screenshot:

    enter image description here

    and then you will see it in .csproj of Android solution.(Unload Android Solution will see this file):

    enter image description here

    In iOS, you will not need to set AOT, because iOS will use AOT as default.

    However, there is a security restriction on iOS, set by Apple, which disallows the execution of dynamically generated code on a device. To ensure that we adhere to these safety protocols, Xamarin.iOS instead uses an Ahead of Time (AOT) compiler to compile the managed code.