Native AOT
Native AOT
Section titled “Native AOT”Native AOT compiles .NET apps to native code for lower memory and fast startup.
Notes
- Not all libraries are compatible; avoid dynamic code generation and reflection-heavy patterns.
Enable Native AOT (csproj)
Section titled “Enable Native AOT (csproj)”<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <PublishAot>true</PublishAot> <InvariantGlobalization>true</InvariantGlobalization> <TrimMode>full</TrimMode> </PropertyGroup></Project>
Publish:
dotnet publish -c Release -r win-x64 --self-contained true
Minimal sample
Section titled “Minimal sample”using System;
Console.WriteLine("Hello AOT!");