What is Native AOT compilation in .NET?

Answer

Native AOT (Ahead-of-Time compilation) compiles .NET applications to a native self-contained executable with no JIT (Just-In-Time) compilation at runtime. Published with: <PublishAot>true</PublishAot>. Benefits: (1) Faster startup: no JIT warm-up — starts in milliseconds (critical for serverless/Lambda). (2) Lower memory: no JIT engine, smaller footprint. (3) Self-contained: no .NET runtime required on the target machine. (4) Security: harder to reverse-engineer. Limitations: (1) No runtime reflection (unless annotated with source generators). (2) No dynamic code generation. (3) Trimming required: unused code is stripped — some libraries aren't trim-compatible. (4) Longer build times. (5) Platform-specific binaries (no portable DLLs). AOT-incompatible features: arbitrary reflection, Activator.CreateInstance without registration, dynamic loading. Use AOT for: Azure Functions, CLI tools, high-density container deployments, Lambda functions.