Files
Htmx/Testing/AOT

AOT Testing Guide

This directory contains scripts for building and testing the Htmx.ApiDemo application with Ahead-of-Time (AOT) compilation enabled. AOT compilation helps identify potential trimming issues that may occur at runtime.

Directory Structure

Testing/
└── AOT/
    ├── build-aot.ps1       # Windows PowerShell script
    ├── build-aot.sh        # Linux/POP_OS bash script
    ├── Publish/            # Output directory (created during build)
    └── README.md           # This file

Prerequisites

  • .NET SDK (version 10.0 or later)
  • For Windows: PowerShell 5.1 or later
  • For Linux/POP_OS: Bash shell

Usage

Windows (PowerShell)

Build and Run:

.\build-aot.ps1

Build Only:

.\build-aot.ps1 -BuildOnly

Run Only (if already built):

.\build-aot.ps1 -RunOnly

Linux/POP_OS (Bash)

Make the script executable first:

chmod +x build-aot.sh

Build and Run:

./build-aot.sh

Build Only:

./build-aot.sh --build-only

Run Only (if already built):

./build-aot.sh --run-only

What These Scripts Do

  1. Clean: Removes any previous publish directory

  2. Build: Publishes the application with the following AOT settings:

    • PublishAot=true - Enables AOT compilation
    • TrimMode=link - Uses link-time trimming
    • PublishTrimmed=true - Enables trimming
    • SelfContained=true - Creates a self-contained executable
    • Debug symbols are disabled for optimized output
  3. Run: Launches the compiled application to test for any trimming-related issues

Output

The compiled application and all dependencies are published to the Testing/AOT/Publish directory.

Troubleshooting

Build Failures

If the AOT build fails, check the error messages for:

  • Trimming issues: Indicates code that cannot be safely trimmed
  • Reflection warnings: APIs that use reflection may not work properly
  • Missing dependencies: Required libraries that aren't properly configured

Common Issues

  1. "Executable not found": The build may have failed silently. Check the build output for errors.
  2. Runtime crashes: Trimming may have removed necessary code. Consider adding trimming configuration in your project file or using [DynamicallyAccessedMembers] attributes.