मुख्य सामग्री पर जाएँ
Skillpedia
डिप्लॉय और क्लाउड (DevOps)5.8k · #14644

dotnet-aot-compat

यह क्या करती है

यह स्किल .NET प्रोजेक्ट को Native AOT और ट्रिमिंग के लिए तैयार करती है। ये सुविधाएँ ऐप को पहले से कंपाइल करने और छोटा आउटपुट देने में मदद करती हैं। यह उन डेवलपर्स के लिए है जिनके आधुनिक .NET बिल्ड में ट्रिम या AOT चेतावनियाँ दिखती हैं।

कब इस्तेमाल करें

  • ✓जब .NET 8 या उसके बाद के वर्शन वाले प्रोजेक्ट में ट्रिमिंग या AOT एनालाइज़र चेतावनियाँ दिखें।
  • ✓जब आप प्रोजेक्ट फ़ाइल में AOT संगतता जाँच चालू करना चाहते हैं।
  • ✓जब रिफ़्लेक्शन कोड को एनोटेशन चाहिए ताकि ट्रिमर सही सदस्य रखे।

Skill का लिंक

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

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/dotnet/skills/blob/main/plugins/dotnet-upgrade/skills/dotnet-aot-compat/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरे .NET 8 ऐप में IL2070 और IL2067 जैसी ट्रिमिंग चेतावनियाँ आ रही हैं। इसे AOT के अनुकूल बना दीजिए।”

हर हफ़्ते 5 नई skills, 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
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills