dotnet-aot-compat
What it does
This skill makes a .NET project ready for Native AOT and trimming, which prepare apps for ahead-of-time compilation and smaller output. It is for developers whose build shows trim or AOT warnings on modern .NET.
When to use it
- βWhen a project targeting .NET 8 or later shows trimming or AOT analyzer warnings.
- βWhen you want to enable AOT compatibility checks in a project file.
- βWhen reflection code needs annotations so the trimmer keeps the right members.
Skill link
https://github.com/dotnet/skills/blob/main/plugins/dotnet-upgrade/skills/dotnet-aot-compat/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βMy .NET 8 app shows trimming warnings like IL2070 and IL2067. Make it AOT compatible.β
5 new skills a week. 1 minute to read.
How it works
The agent enables the compatibility checks, works through each warning, and adds the correct annotations rather than suppressing the warnings.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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.
π‘ Preferred approaches
- Prefer
[DynamicallyAccessedMembers]annotations to flow type information through the call chain. - Prefer refactoring to eliminate patterns that break annotation flow (e.g., boxing
Typethroughobject[]). - Use
[RequiresUnreferencedCode]/[RequiresDynamicCode]/[RequiresAssemblyFiles]to mark methods as fundamentally incompatible with trimming, propagating the requirement to callers. This surfaces the issue clearly rather than hiding it β callers must explicitly acknowledge the incompatibility.
Annotation flow is key
The trimmer tracks [DynamicallyAccessedMembers] annotations through assignments, parameter passing, and return values. If this flow is broken (e.g., by boxing a Type into object, storing in an untyped collection, or casting through interfaces), the trimmer loses track and warns. The fix is to preserve the flow, not suppress the warning.
Step-by-Step Procedure
Do not explore the codebase up-front. The build warnings tell you exactly which files and lines need changes. Follow a tight loop: build β pick a warning β open that file at that line β apply the fix recipe β rebuild. Reading or analyzing source files beyond what a specific warning points you to is wasted effort and leads to timeouts. Let the compiler guide you.
β Do NOT run
find,ls, orgrepto understand the project structure before building. Do NOT read README, docs, or architecture files. Your first action should be Step 1 (enable AOT analysis), then build.
Step 1: Enable AOT analysis in the .csproj
Add IsAotCompatible. If the project doesn't exclusively target net8.0+, add a TFM condition (AOT analysis requires net8.0+):
<PropertyGroup>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>
</PropertyGroup>
This automatically sets EnableTrimAnalyzer=true and EnableAotAnalyzer=true for compatible TFMs. For multi-targeting projects (e.g., netstandard2.0;net8.0), the condition ensures no NETSDK1210 warnings on older TFMs.
Step 2: Build and collect warnings
dotnet build <project.csproj> -f <net8.0-or-later-tfm> --no-incremental 2>&1 | grep 'IL[0-9]\{4\}'
Sort and deduplicate. Common warning codes:
- IL2070: Reflection call on a
Typeparameter missing[DynamicallyAccessedMembers] - IL2067: Passing an unannotated
Typeto a method expecting[DynamicallyAccessedMembers] - IL2072: Return value or extracted value missing annotation (often from unboxing)
- IL2057:
Type.GetType(string)with a non-constant argument - IL2026: Calling a method marked `[RequiresUnreferencedCode
FAQ
Can I just hide the warnings?
The skill advises against it. Warnings should be fixed with the right annotations, since hiding them can cause runtime failures.
Does it publish a Native AOT binary?
No. Publishing native binaries and reducing binary size are outside this skill.
Does it work on .NET Framework?
No. The analyzers do not apply to .NET Framework projects.
Details
Original description by the author
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.
repo: dotnet/skills
Popularity
- GitHub stars
- 5.8k
- Ranking position
- #14644
- License
- MIT
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
create-custom-agent
5.8kHelps your agent create VS Code custom agent files with their own tools, instructions and handoffs to other agents.
create-skill
5.8kHelps your agent create a new agent skill with a valid name, a clear trigger description and a SKILL.md file that follows the standard.
csharp-scripts
5.8kHelps your agent run a small C# program as a single file with the .NET command line tool, without creating a full project.
dotnet-pinvoke
5.8kHelps your agent call native C or C++ libraries from .NET correctly, covering signatures, string handling, memory and safe handles.
Similar skills
openclaw-update
394kHelps your agent update an existing OpenClaw Gateway, choosing the update method that fits how it was installed and keeping your session working.
diagnose-gateway
394kHelps your agent find out why your OpenClaw Gateway is failing by checking settings, channels, and ports without changing anything.
crabbox-apps
394kHelps your agent open and run an app on a temporary cloud machine, then show its view in your chat side panel.