Álvaro García
Álvaro García

Reputation: 19356

How to enabled AOT compiler in .NET 6? Is Crossgen2 the same than AOT?

I have read that to enabled AOT I have to edit the project file and add this line:

<Propertygroup>
    <RunAOTCompilation>True</RunAOTCompilation>
</PropertyGroup>

But the intellisense don't give me this option, so I don't know if in .NET 6 this is different.

Also I have read that ready to run it is not the same than AOT, because ready to run still it keeps de CLR language and it can be used for any platform, instead AOT is specific for the platform. I could read here.

How could I enabled AOT and how could I test if it is enabled correctly?

Thanks.

Upvotes: 0

Views: 4034

Answers (2)

Tejas Shede
Tejas Shede

Reputation: 23

You can simply set up in publish profile by checking the checkbox "Enable ReadyToRun Compilation"

Check attached screenshot

ReadyToRun is a Form of AOT Compilation. More About R2R.

Upvotes: 1

E.Benedos
E.Benedos

Reputation: 1767

Considering you are probably speaking about a Blazor WebAssembly project you can also simply enable AOT compilation directly from Visual Studio 2022 on project properties menu (or by project file edit):

enter image description here

For all the other types of projects you can use the ReadyToRun compilation that is something similar but not a full AOT compilation. It is a performance improvement mainly for startup process.

Regarding .NET 7 Preview Microsoft has been implemented a real AOT compilation but unfortunately not already wide supported by all libraries.

Upvotes: 1

Related Questions