
Dotnet Aot Compat
Make .NET projects compatible with Native AOT and trimming by systematically resolving...
Install
npx skills add managedcode/dotnet-skills --skill dotnet-aot-compat -g -a claude-code -y- Repository
- managedcode/dotnet-skills500
- Category
- Engineering
- Updated
- 6d ago
- License
- MIT
- Context cost
- Mediumabout 3,000 tokens
- Runs scripts
- No, instructions only
What it does
Make .NET projects compatible with Native AOT and trimming by systematically resolving IL trim/AOT analyzer warnings. USE FOR: making projects AOT-compatible, fixing trimming warnings, resolving IL warnings (IL2026, IL2070, IL2067, IL2072, IL3050), adding DynamicallyAccessedMembers annotations, enabling IsAotCompatible. DO NOT USE FOR: publishing native AOT binaries, optimizing binary size, replacing reflection-heavy libraries with alternatives. INVOKES: no tools, pure knowledge skill.
dotnet-aot-compat
Make .NET projects compatible with Native AOT and trimming by systematically resolving all IL trim/AOT analyzer warnings.
When to Use This Skill
- "Make this project AOT-compatible"
- "Fix trimming warnings" or "fix IL warnings"
- "Resolve IL2070 / IL2067 / IL2072 / IL2026 / IL3050 warnings"
- "Add DynamicallyAccessedMembers annotations"
- "Enable IsAotCompatible in my .csproj"
- "My project has trim analyzer warnings after upgrading to net8.0"
- "Annotate reflection code for the trimmer"
When Not to Use This Skill
Do not use this skill when the project exclusively targets .NET Framework (net4x), which does not support the trim/AOT analyzers.
Prerequisites
An existing .NET project targeting net8.0 or later (or multi-targeting with at least one net8.0+ TFM) and the corresponding .NET SDK installed.
Background: What AOT Compatibility Means
Native AOT and the IL trimmer perform static analysis to determine what code is reachable. Reflection can break this analysis because the trimmer can't see what types/members are accessed at runtime. The IsAotCompatible property enables analyzers that flag these issues as build warnings (ILXXXX codes).
Critical Rules
❌ Never suppress warnings incorrectly
- NEVER use
#pragma warning disablefor IL warnings. It hides warnings from the Roslyn analyzer at build time, but the IL linker and AOT compiler still see the issue. The code will fail at trim/publish time. - NEVER use
[UnconditionalSuppressMessage]. It tells both the analyzer AND the linker to ignore the warning, meaning the trimmer cannot verify safety. Raising an error at build time is always preferable to hiding the issue and having it silently break at runtime.
