본문으로 건너뛰기
Skillpedia
배포 및 클라우드 (DevOps)5.8k · #14644

dotnet-aot-compat

하는 일

이 스킬은 .NET 프로젝트를 Native AOT와 트리밍에 준비시킵니다. 앱을 미리 컴파일하고 출력 크기를 줄이는 것을 뜻합니다. 최신 .NET에서 빌드가 트리밍이나 AOT 경고를 보여 주는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓.NET 8 이상 프로젝트에서 트리밍이나 AOT 분석기 경고가 나타날 때.
  • ✓프로젝트 파일에서 AOT 호환성 검사를 켜고 싶을 때.
  • ✓트리머가 올바른 멤버를 유지하도록 리플렉션 코드에 주석이 필요할 때.

스킬 링크

https://github.com/dotnet/skills/blob/main/plugins/dotnet-upgrade/skills/dotnet-aot-compat/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/dotnet/skills/blob/main/plugins/dotnet-upgrade/skills/dotnet-aot-compat/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 .NET 8 앱에서 IL2070, IL2067 같은 트리밍 경고가 나옵니다. Native AOT와 호환되도록 만들어 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트가 호환성 검사를 켜고, 경고를 하나씩 살펴보며, 경고를 숨기지 않고 올바른 주석을 추가합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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 disable for 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 Type through object[]).
  • 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, or grep to 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 Type parameter missing [DynamicallyAccessedMembers]
  • IL2067: Passing an unannotated Type to 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
자주 묻는 질문

경고를 그냥 숨겨도 되나요?

이 스킬은 권하지 않습니다. 경고를 숨기면 실행 중 실패가 생길 수 있으므로 올바른 주석으로 고쳐야 합니다.

Native AOT 바이너리를 게시하나요?

아니요. 네이티브 바이너리 게시와 바이너리 크기 줄이기는 이 스킬의 범위 밖입니다.

.NET Framework에서도 되나요?

아니요. 분석기는 .NET Framework 프로젝트에는 적용되지 않습니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
5.8k
순위
#14644
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬