Reduced size AOT /5 (#29348)

* Reduced size AOT /5

* Reduced size AOT /5

* Reduced size AOT /5

* Reduced size AOT /5

* Reduced size AOT /5
pull/29357/head
Rick Anderson 2023-05-24 10:36:46 -10:00 committed by GitHub
parent 15cac7a5bd
commit 9ddb0eb390
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -5,7 +5,7 @@ description: Learn about ASP.NET Core support for native AOT
monikerRange: '>= aspnetcore-8.0'
ms.author: midenn
ms.custom: mvc
ms.date: 5/5/2023
ms.date: 5/25/2023
uid: fundamentals/native-aot
---
# ASP.NET Core support for native AOT
@ -141,7 +141,7 @@ Mode LastWriteTime Length Name
-a--- 30/03/2023 1:41 PM 43044864 MyFirstAotWebApi.pdb
```
The executable is self-contained and doesn't require a .NET runtime to run. When launched it should behave the same as the app run in the development environment. Run the AOT app:
The executable is self-contained and doesn't require a .NET runtime to run. When launched, it should behave the same as the app run in the development environment. Run the AOT app:
```cli
.\bin\Release\net8.0\win-x64\publish\MyFirstAotWebApi.exe
@ -232,19 +232,24 @@ The AOT version of `launchSettings.json` file is simplified and has the `iisSett
<xref:System.Text.Json.Serialization.JsonSerializerContext>:
* Is used in the tempate and shown in the preceding highlighted code.
* Is used in the template and shown in the preceding highlighted code.
* Enables JSON serialization with native AOT.
* Specifies the custom types that are needed to serialize.
* Is used by the [JSON source generator](/dotnet/standard/serialization/system-text-json/source-generation) to produce code.
The <xref:Microsoft.AspNetCore.Builder.WebApplication.CreateSlimBuilder>:
<a name="csb"></a>
<xref:Microsoft.AspNetCore.Builder.WebApplication.CreateSlimBuilder>:
* Initializes the <xref:Microsoft.AspNetCore.Builder.WebApplicationBuilder> with the minimal ASP.NET Core features necessary to run an app.
* Is added by the template whether or not the AOT option is used.
* By default, doesn't include support for HTTPS or HTTP/3. HTTPS and HTTP/3:
* Typically aren't required for apps run behind a TLS termination proxy. For example, when using [TLS termination and end to end TLS with Application Gateway](/azure/application-gateway/ssl-overview).
* Can be enabled by calling [builder.WebHost.UseQuic](xref:Microsoft.AspNetCore.Hosting.WebHostBuilderQuicExtensions.UseQuic%2A) or [builder.WebHost.UseKestrelHttpsConfiguration](https://source.dot.net/#Microsoft.AspNetCore.Server.Kestrel/WebHostBuilderKestrelExtensions.cs,fcec859000ccaa50) <!-- TODO replace with xref: (xref:Microsoft.AspNetCore.Hosting.WebHostBuilderKestrelExtensions.UseKestrel%2A) -->
:::code language="csharp" source="~/fundamentals/aot/samples/Program.cs" highlight="4":::
Because unused code is trimmed during publishing for native AOT, the app can't use unbounded reflection at runtime. Source generators are used to produce code to avoid the need for reflection. In some cases source generators produce code optimized for AOT even when a generator is not required. To view source code that is generated based on the code in `Program.cs` add the [`<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>`](/dotnet/csharp/roslyn-sdk/source-generators-overview) property to `MyFirstAotWebApi.csproj`:
Because unused code is trimmed during publishing for native AOT, the app can't use unbounded reflection at runtime. Source generators are used to produce code to avoid the need for reflection. In some cases, source generators produce code optimized for AOT even when a generator is not required. To view source code that is generated based on the code in `Program.cs` add the [`<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>`](/dotnet/csharp/roslyn-sdk/source-generators-overview) property to `MyFirstAotWebApi.csproj`:
```xml
<Project Sdk="Microsoft.NET.Sdk.Web">
@ -310,7 +315,7 @@ Not all features in ASP.NET Core are currently compatible with native AOT. The f
| StaticFiles | <span aria-hidden="true">✔️</span><span class="visually-hidden">Fully supported</span> | | |
| WebSockets | <span aria-hidden="true">✔️</span><span class="visually-hidden">Fully supported</span> | | |
It's important to test the app thoroughly when moving to a native AOT deployment model. The AOT deployed app should be tested to verify functionality hasn't changed fron the untrimmed and JIT-compiled app. When building the app, review and correct AOT warnings. An app that issues AOT warnings during publishing is not guaranteed to work correctly. If no AOT warnings are issued at publish time, the pubished AOT app should work the same as when run in development.
It's important to test the app thoroughly when moving to a native AOT deployment model. The AOT deployed app should be tested to verify functionality hasn't changed from the untrimmed and JIT-compiled app. When building the app, review and correct AOT warnings. An app that issues AOT warnings during publishing is ***not*** guaranteed to work correctly. If no AOT warnings are issued at publish time, the published AOT app should work the same as when run in development.
For more information on AOT warnings and how to address them see [Introduction to AOT warnings](/dotnet/core/deploying/native-aot/fixing-warnings).