Skip to content

Native AOT deployment

Publishing your app as Native AOT produces an app that's self-contained and that has been ahead-of-time (AOT) compiled to native code. Native AOT apps have faster startup time and smaller memory footprints. These apps can run on machines that don't have the .NET runtime installed.

The benefit of Native AOT is most significant for workloads with a high number of deployed instances, such as cloud infrastructure and hyper-scale services. .NET 8 adds ASP.NET Core support for native AOT.

The Native AOT deployment model uses an ahead-of-time compiler to compile IL to native code at the time of publish. Native AOT apps don't use a just-in-time (JIT) compiler when the application runs.

Native AOT apps can run in restricted environments where a JIT isn't allowed.

Native AOT applications target a specific runtime environment, such as Linux x64 or Windows x64, just like publishing a self-contained app.

Limitations of Native AOT deployment

Native AOT apps have the following limitations:

  • No dynamic loading, for example, Assembly.LoadFile.
  • No run-time code generation, for example, System.Reflection.Emit.
  • No C++/CLI.
  • Windows: No built-in COM.
  • Requires trimming, which has limitations.
  • Implies compilation into a single file, which has known incompatibilities.
  • Apps include required runtime libraries (just like self-contained apps, increasing their size as compared to framework-dependent apps).
  • System.Linq.Expressions always use their interpreted form, which is slower than run-time generated compiled code.
  • Generic parameters substituted with struct type arguments have specialized code generated for each instantiation. In the dynamic runtime, many instantiations are generated on-demand. In Native AOT, all instantiations are pre-generated. This can have significant impact to the disk size of the application. Generic virtual methods and generic instance methods will also have an instantiation for every implementing or overriding type.
  • Not all the runtime libraries are fully annotated to be Native AOT compatible. That is, some warnings in the runtime libraries aren't actionable by end developers.
  • Diagnostic support for debugging and profiling with some limitations.
  • Support for some ASP.NET Core features. For more information, see ASP.NET Core support for Native AOT.

The publish process analyzes the entire project and its dependencies for possible limitations. Warnings are issued for each limitation the published app might encounter at run time.

See Also

The above was taken from the Microsoft documentation. For more details please refer to this documentation.