Skip to main content

Command Palette

Search for a command to run...

Tiny, fast ASP.NET Core APIs with native AOT | .NET Conf 2023

Published
1 min read
Tiny, fast ASP.NET Core APIs with native AOT | .NET Conf 2023
İ

An agile-minded senior developer with a proven track record spanning over 15 years of developing innovative end-to-end business solutions. Have experience in architecture, development, test, UX, and team lead. Designed, led, developed, and released solutions for different areas including eLearning, law, telecommunication, travel&tourism, insurance, and fraud detection. Focus on clean architecture, clean code, and satisfied customers. Tech stack is mainly full-stack development in the .NET ecosystem and Azure.

.NET 8 introduces support for publishing ASP.NET Core applications to native AOT for lightning-fast startup times & small, self-contained, native executables & containers. This session will provide an overview of when you might want to consider publishing native AOT for your ASP.NET Core APIs and demonstrate the benefits and compatibility considerations.

Why AOT?

  • Smaller apps

  • Faster startups

  • Less memory usage

Demo

Create a new Api Project and publish. The output is as below.

Self Contained Deployment

By default, the output is framework-dependent. If you want your output independent of the running environment, you may use self-contained. This will include the framework.

Output will include the framework runtime which makes the size very large.

How will Native AOT Will Help?

Enable Nati AOT by adding below to csproj.

<PublishAot>true</PublishAot>

WebApplication.CreateSlimBuilder()

It has fewer defaults and is lighter. Use with Native AOT.

The output will have approximately 10 MB for Windows.

WebApplication.CreateEmptyBuilder()

It creates an empty builder but you need to configure what you need. The output will be smaller.

Reference

https://www.youtube.com/watch?v=FpQXyFoZ9aY&list=PLdo4fOcmZ0oULyHSPBx-tQzePOYlhvrAU&index=20