What is .NET Native AOT and when should you use it?

Native AOT has been around since .NET 7, but I still keep meeting developers who are not quite sure what it actually is. Is it just a faster build? Can I use it with my existing app? Well, this blog post is here to help. I will go through what Native AOT is, what you gain and why the f*** you should care about.
JIT vs Native AOT
Normally when you build a C# app, the compiler does not produce machine code that your CPU can run directly. It produces IL (intermediate language), which is a kind of half-baked format that is the same for every platform. That is why the same .dll can run on Windows, Linux and macOS.
Something needs to turn the IL into real machine code before the app can run… well real might be a bad wording here, but a code that machine can run natively! In normal .NET apps that something is the JIT (just-in-time) compiler, which is part of the .NET runtime. When you start the app, the JIT compiles your methods to machine code on the fly, the first time each method is called. This is flexible, but it costs some time and memory every time the app starts.
Native AOT (ahead-of-time) moves that work to publish time. When you run dotnet publish, the compiler turns your IL into machine code right away, and the result is a native executable, just like what you would get from C++ or Go. No JIT at runtime.
Think of it like cooking. JIT is cooking the meal when the customer orders it. AOT is cooking it beforehand (we all love those buffets), so it is ready when the customer arrives. Prepared food is served faster, but you need to know in advance what the customer wants.

JIT cooks to order, Native AOT is the buffet that is ready when you arrive.
The compiled result is a self-contained app that does not need the .NET runtime installed on the target machine. The app itself contains a small version of the runtime (for example the garbage collector that cleans up your memory), so “no runtime” really means no separate .NET installation.
What do you gain💪?
- Faster startup. There is no JIT warm-up, so the app is ready to go almost immediately. This is great for CLI tools, serverless functions and containers that start often.
- Smaller memory footprint. The app uses less memory, which matters when you run a lot of copies of it, like in the cloud. The real benefit depends on your use case thou…
- Easy deployment. Copy the executable to a machine and run it. No .NET installation needed.
- Works where JIT is not allowed. Some locked-down environments simply do not allow generating code at runtime.
What do you give up?
Of course Native AOT is not only fairytale and there are some trade-offs also like in everything in tech. Native AOT needs to know all the code your app needs at publish time. Everything that is decided only when the app is running becomes a problem. Here is what that means in practice:
- Reflection is limited. Reflection means looking at types at runtime, for example finding all properties of a class by name with
typeof(Person).GetProperties(). The compiler can’t always know which types you will inspect, so it may remove code that you need. Many popular libraries (serializers, dependency injection, mappers) use reflection internally. - No dynamic loading. You can’t load a
.dllat runtime withAssembly.LoadFile, so plugin systems don’t work. - No runtime code generation. Things like
System.Reflection.Emitthat create new code while the app is running are out. - Trimming. To keep the executable small, the compiler removes all code it thinks you don’t use. This is called trimming, and it is the reason why the reflection problems above happen.
- No built-in COM or C++/CLI. This matters mostly for good old Windows interop code.
- One build per platform. You publish for a specific target like
win-x64orlinux-arm64(called a runtime identifier, RID). A Linux build only runs on the same or newer Linux version than it was built on. - Bigger binaries in some cases. Since all the code is generated in advance, generic code can get a separate copy for each struct type you use it with, which makes the file larger.
The way I think about this is: less runtime cleverness, more build-time explicitness. The most common way to get there is to replace reflection with source generators. These are tools that write the code for you at build time, so the compiler can see everything. For example System.Text.Json has a source generator that works nicely with Native AOT. In my opinion that is not a bad thing at all, because clever runtime magic is also the thing that is hard to debug at 3 AM.
When you publish, you get a warning for each thing that might break at runtime. Don’t suppress the warnings lightly like we do normally, especially the RequiresDynamicCode ones.
How is this different from ReadyToRun?
You might have heard of ReadyToRun (Not R2D2, but R2R), which is another option in .NET that sounds similar. With ReadyToRun the IL is still there, and you get some pre-compiled machine code next to it. The runtime and the JIT are still used, but they have less work to do at startup. So you get faster startup without giving up reflection or other dynamic features.
Using the cooking analogy: ReadyToRun is like prepping the ingredients beforehand, but you still cook when the customer orders. Native AOT is the fully prepared meal.
| JIT (default) | ReadyToRun | Native AOT | |
|---|---|---|---|
| Needs .NET installed | Yes | Yes | No |
| Uses JIT at runtime | Yes | Partly | No |
| Startup | Normal | Faster | Fastest |
| Compatibility | Everything works | Everything works | Some things don’t work |
ReadyToRun is a good first step if you want better startup and don’t want to lose any compatibility.
Try it yourself
Trying Native AOT is easier than you might think. First, the prerequisites. On Windows you need Visual Studio 2022 or later with the Desktop development with C++ option. On Linux you need clang (for example sudo apt-get install clang on Ubuntu), and on macOS the Xcode command line tools.
Then add one property to your project file:
<PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup>
It is better to put this in the project file rather than on the command line, because it also turns on the AOT analyzers while you write code. So you see warnings in your IDE long before you publish.
Then publish for a specific platform:
dotnet publish -r win-x64 -c Release
The executable ends up in the publish folder, and you can just run it. Next to it is a debug symbol file (.pdb on Windows), which you need if you want to debug or investigate crashes.
The publish process checks your whole project and its dependencies, and gives you a warning for each thing that might break at runtime.
Supported platforms
Native AOT works on Windows, Linux and macOS (x64 and Arm64), and newer .NET versions add more, like iOS. ASP.NET Core supports Native AOT starting from .NET 8, but only a subset of its features. You can find the full table from the official docs.
What does Native AOT mean for an everyday .NET developer?
Honest answer: for most of us, not much as of today. Native AOT is opt-in. If you don’t set PublishAot, nothing changes. Your ASP.NET Core web app, your Blazor app, your WPF tool and your Azure Function with EF Core keep running on the normal JIT, and that is a perfectly fine.
So if you build typical line-of-business apps, you can safely say “I don’t need this” and move on. Your app probably starts once and runs for days, so a few hundred milliseconds of startup means nothing.
It starts to mean something when:
- You build small tools or services that start often, like CLI tools, MCP servers, serverless functions or containers that scale to zero. Startup time and memory are what you pay for there.
- You need to ship a single executable to people who don’t have .NET installed.
- You write NuGet libraries. Even if you never use AOT yourself, your users might.
There is also a longer-term effect that you may notice even without using AOT: the .NET ecosystem is slowly moving from reflection towards source generators. You see it as [JsonSerializable] contexts, [GeneratedRegex], the LoggerMessage generator and minimal API generators. Learning to read the trim and AOT warnings is a useful skill even if you never publish a native app.
Why Native AOT matters in the AI era
AI is everywhere these days, so of course I have to talk about it here too. Microsoft’s docs don’t talk about AI specifically, so this is my own take, but the benefits they list (faster startup, lower memory, smaller files, single executable) map nicely to a few typical AI scenarios:
- MCP servers and AI tools. A local MCP server is usually started by your AI client (VS Code, Copilot CLI and so on) as its own process. Startup time is felt directly there. A single native executable that starts instantly and doesn’t need .NET installed is a lot easier to share with your team than “install the right SDK first”.
- Tools for AI agents. An AI agent can call command line tools many times in one task. Every call pays the startup cost, so a tool that starts instantly makes the whole thing feel snappier.
- JSON everywhere. Tool calls and structured LLM outputs are mostly JSON in, JSON out. The
System.Text.Jsonsource generator works well with Native AOT, so you get strongly typed JSON handling without reflection.
Building a library?
If you maintain a NuGet library and want to tell the world that it works with Native AOT, set IsAotCompatible to true. It turns on the analyzers that warn you about AOT problems in your code:
<PropertyGroup>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
Target at least net8.0, because that is when the AOT analysis warnings were introduced. If you also support older frameworks, multi-target and enable the property only for net8.0 and later. The docs show how.
Summary
Native AOT is not a magic “make it faster” checkbox. It is a trade: you give up a bit of the dynamic side of .NET and in return you get fast startup, a smaller footprint and simple deployment. Should you start using it immediately? Not for everything, but if you are starting a new small service or tool, you can try it out. Just set PublishAot, fix the warnings and see what you get. If your app is full of reflection, start with ReadyToRun instead and come back to AOT later.