Native AOT is an optimized .NET runtime deployment model. This document will guide you through compiling a .NET Console application with native AOT.
Please ensure that pre-requisites are installed.
Open a new shell/command prompt window and run the following commands.
> dotnet new console -o HelloWorld --aot
> cd HelloWorldThis will create a simple Hello World console app in Program.cs and associated project files enabled for publishing as native AOT.
Once the package has been successfully added it's time to compile and publish your app! In the shell/command prompt window, run the following command:
> dotnet publishOnce completed, you can find the native executable in the root folder of your project under /bin/<Configuration>/net8.0/<RID>/publish/. Navigate to /bin/<Configuration>/net8.0/<RID>/publish/ in your project folder and run the produced native executable.
This sample includes Dockerfiles that demonstrate installing NativeAOT build prerequisites and building in a container:
- Linux x64:
docker build -t hello . & docker run -t hello - Windows x64:
docker build -t hello -f Dockerfile.windowsservercore-x64 . & docker run -t hello
More comprehensive containerized sample app built with native AOT can be found in dotnet-docker repo.