dotnet-aot-compat
Qué hace
Esta skill prepara un proyecto de .NET para Native AOT y el recorte (trimming), que preparan las aplicaciones para compilación anticipada y una salida más pequeña. Es para desarrolladores cuya compilación muestra advertencias de recorte o AOT en .NET moderno.
Cuándo usarla
- ✓Cuando un proyecto que usa .NET 8 o posterior muestra advertencias de recorte o AOT del analizador.
- ✓Cuando quieres activar las comprobaciones de compatibilidad AOT en el archivo de proyecto.
- ✓Cuando el código de reflexión necesita anotaciones para que el recortador conserve los miembros correctos.
Link de la skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-upgrade/skills/dotnet-aot-compat/SKILL.mdCópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.
Cómo usar
La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.
Mensaje listo para pegar
Para Claude Code, Codex o Cursor: ejecútalo en la carpeta del proyecto y la skill queda instalada.
Descarga el SKILL.md y ponlo en la carpeta de skills de tu agente.
Ejemplo de qué pedirle a la IA
“Mi aplicación de .NET 8 muestra advertencias de recorte como IL2070 e IL2067. Hazla compatible con AOT.”
5 skills nuevas por semana. 1 minuto de lectura.
Cómo funciona
El agente activa las comprobaciones de compatibilidad, revisa cada advertencia y añade las anotaciones correctas en lugar de silenciarlas.
Contenido técnico (SKILL.md original)
Texto original del autor, en inglés, directo de 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
Preguntas frecuentes
¿Puedo simplemente ocultar las advertencias?
La skill lo desaconseja. Las advertencias deben corregirse con las anotaciones adecuadas, porque ocultarlas puede causar fallos en tiempo de ejecución.
¿Publica un binario de Native AOT?
No. Publicar binarios nativos y reducir su tamaño quedan fuera de esta skill.
¿Funciona con .NET Framework?
No. Los analizadores no se aplican a proyectos de .NET Framework.
Detalles
Descripción original del autor
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
Popularidad
- Estrellas en GitHub
- 5,8 mil
- Posición en el ranking
- #14644
- Licencia
- MIT
- Actualizada
- 2/11/2026
Comentarios
- …
Más skills de este repositorio
create-custom-agent
5,8 milAyuda a tu agente a crear archivos de agentes personalizados de VS Code, con sus propias herramientas, instrucciones y traspasos a otros agentes.
create-skill
5,8 milAyuda a tu agente a crear una skill nueva de agente con un nombre válido, una descripción de activación clara y un archivo SKILL.md que siga el estándar.
csharp-scripts
5,8 milAyuda a tu agente a ejecutar un pequeño programa en C# como un único archivo con la herramienta de línea de comandos de .NET, sin crear un proyecto completo.
dotnet-pinvoke
5,8 milAyuda a tu agente a llamar correctamente a librerías nativas de C o C++ desde .NET, cubriendo firmas, manejo de cadenas, memoria y handles seguros.
Skills parecidas
openclaw-update
394 milAyuda a tu agente a actualizar una Gateway de OpenClaw que ya existe, eligiendo el método de actualización que encaja con cómo se instaló y manteniendo tu sesión activa.
diagnose-gateway
394 milAyuda a tu agente a averiguar por qué falla tu Gateway de OpenClaw, revisando ajustes, canales y puertos sin cambiar nada.
crabbox-apps
394 milAyuda a tu agente a abrir y ejecutar una app en una máquina temporal en la nube y mostrar su vista en el panel lateral de tu chat.