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

.NET 8 introduces support for publishing [ASP.NET](http://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](http://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](https://github.com/ibrahimuludag/native-aot/commit/d541c8c1b5f48abc3f7323b5d4f6384906fbdc0f) and publish. The output is as below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703264503202/3aa52b4f-ada4-4d18-9c6e-282e687e30cd.png align="center")

## 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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703264926645/c117eb2a-900b-42ed-971a-35143152b6f3.png align="center")

## How will Native AOT Will Help?

Enable Nati AOT by adding below to csproj.

```csharp
<PublishAot>true</PublishAot>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703264984366/4a6dacf0-ad7c-4670-8f27-2b450885aaf6.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703265169966/4f7f76bd-75a2-4147-8b48-af834f2609c6.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703265673197/5983bc49-cc75-489d-8a73-03ee24bbd835.png align="center")

## 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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703266491973/a37dbe8a-77e4-4528-a37a-9e47efc07a02.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703266692682/c089816e-4473-4131-adb3-b82e36143fc1.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703266712434/dc46d801-f69d-4a0a-94ce-e6fdfd1e13c1.png align="center")

## Reference

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