📦 One EXE, No Runtime, Instant Start
.NET apps need runtime installed. Native AOT compiles to single native executable. Works on machines without .NET. 10ms startup.
🔧 Enable Native AOT
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>
# Publish command
dotnet publish -c Release -r win-x64 --self-contained
# Output: single .exe file (~10-30MB)
🎯 AOT Limitations
// ❌ Reflection (some may work, some not)
Type.GetType("SomeType") // May return null
// ❌ Dynamic code generation
Assembly.Load(byte[]) // Not supported
// ❌ Newtonsoft.Json (uses reflection heavily)
// Use System.Text.Json with source generation instead
// ✅ Source-generated serialization
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(MyClass))]
internal partial class MyJsonContext : JsonSerializerContext { }
var json = JsonSerializer.Serialize(obj, MyJsonContext.Default.MyClass);
✅ Perfect For
- CLI tools (git-like, small, fast)
- AWS Lambda/Azure Functions (cold start elimination)
- Microservices in containers (small images)
- Embedded/IoT devices (no runtime install)
“CLI tool required .NET runtime on customer machines. Native AOT compiled to single 15MB .exe. Customers copy and run. No install, no dependencies. Game changer.”
