Token导航 LogoToken导航

Agent Skill · 研究检索

dotnet-aot-compat(dotnet aot 兼容)

dotnet-aot-compat 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

dotnet-aot-compat 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为只读;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 19,336。

总安装 5,655周安装 231GitHub Stars 1,479下载 1,830核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dotnet-aot-compat(dotnet aot 兼容)
来源仓库:https://github.com/dotnet/skills
仓库路径:skills/dotnet-aot-compat
安装命令:
npx skills add https://github.com/dotnet/skills --skill dotnet-aot-compat
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dotnet/skills --skill dotnet-aot-compat

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

dotnet-aot-compat 使 .NET 项目兼容 Native AOT 和 trimming,系统性解决 IL 警告。适合在 Codex、Claude、Cursor、Gemini CLI 中需要修复 IL2070、IL2067 等 trim 警告时使用。

通过 GitHub 安装,提供 DynamicallyAccessedMembers 注解和 IsAotCompatible 配置。使用前需确认项目不 exclusively targeting .NET Framework,并了解 trim-safe 编程模式。

适用于需要减小部署包大小和提升启动性能的 .NET 项目,特别是云原生应用。

来源仓库内路径:skills/dotnet-aot-compat

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/dotnet/skills --skill dotnet-aot-compat;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它标注为只读,先用只读任务试一次,确认行为符合预期再扩大使用范围。

常见问题

6 条

dotnet-aot-compat 怎么安装?

在终端执行 npx skills add https://github.com/dotnet/skills --skill dotnet-aot-compat。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

dotnet-aot-compat 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

dotnet-aot-compat 需要什么权限?

权限级别是只读。该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

dotnet-aot-compat 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

dotnet-aot-compat 用的人多吗?

公开数据是累计安装 5,655 次,近一周安装 231 次,下载 1,830 次,GitHub 1,479 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

dotnet-aot-compat 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。
  • 来源仓库有 1,479 星,维护活跃度相对可查。
  • 标注为只读权限,试用阶段不容易误改本地文件。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。
  • 只想先试试效果、不希望它改动本地文件的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
dotnet-aot-compat

dotnet aot 兼容 · 本页

5,6551,479只读未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

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]
  • IL2050: P/invoke method with COM marshalling parameters
  • IL2075: Return value flows into reflection without annotation
  • IL2091: Generic argument missing [DynamicallyAccessedMembers] required by constraint
  • IL3000: Assembly.Location returns empty string in single-file/AOT apps
  • IL3050: Calling a method marked [RequiresDynamicCode]

Step 3: Triage warnings by code (do NOT read every file)

Group the warnings from Step 2 by warning code and count them. Do not open individual files yet. Identify the top 1-2 patterns by count — these drive your fix strategy:

PatternTypical fix
Many IL2026 + IL3050 from JsonSerializerGo to Strategy C immediately — create a JsonSerializerContext, then batch-update all call sites
IL2070/IL2087 on Type parametersAdd [DynamicallyAccessedMembers] to the innermost method, then cascade outward
IL2067 passing unannotated TypeAnnotate the parameter at the source

In most real projects, IL2026/IL3050 from JsonSerializer dominate. Start with Strategy C unless the warning breakdown clearly shows otherwise. After the batch JSON fix, handle remaining warnings with Strategies A–B. Only use Strategy D as a last resort.

Step 4: Fix warnings iteratively (innermost first)

Work from the innermost reflection call outward. Each fix may cascade new warnings to callers.

Stay warning-driven. For each warning, open only the file and line the compiler reported, identify the pattern, apply the matching fix recipe below, and move on. Do not scan the codebase for similar patterns or try to understand the full architecture — fix what the compiler tells you, rebuild, and let new warnings guide the next change. Fix a small batch of warnings (5-10), then rebuild immediately to check progress.

Use sub-agents when available. If you can launch sub-agents (e.g., via a task tool), dispatch multiple sub-agents in parallel to edit different files simultaneously. Keep the main loop focused on building, parsing warnings, and dispatching — delegate actual file edits to sub-agents. For batch JSON updates, give each sub-agent 5-10 files to update in one prompt. After 2 build-fix cycles, dispatch all remaining file edits to sub-agents in parallel — do not continue fixing files sequentially. Example:

Update these files to use source-generated JSON: src/Models/Resource.Serialization.cs, src/Models/Identity.Serialization.cs, src/Models/Plan.Serialization.cs. In each file, replace JsonSerializer.Serialize(writer, value) with JsonSerializer.Serialize(writer, value, MyProjectJsonContext.Default.TypeName) and JsonSerializer.Deserialize<T>(ref reader) with JsonSerializer.Deserialize(ref reader, MyProjectJsonContext.Default.TypeName). Only edit the JsonSerializer call sites.
Strategy A: Add [DynamicallyAccessedMembers] (preferred)

When a method uses reflection on a Type parameter, annotate the parameter to tell the trimmer what members are needed:

using System.Diagnostics.CodeAnalysis;

// Before (warns IL2070):
void Process(Type t) {
    var method = t.GetMethod("Foo");  // trimmer can't verify
}

// After (clean):
void Process([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type t) {
    var method = t.GetMethod("Foo");  // trimmer preserves public methods
}

When you annotate a parameter, all callers must now pass properly annotated types. This cascades outward — follow each caller and annotate or refactor as needed. The caller's annotation must include at least the same member types as the callee's. If the callee requires PublicConstructors | NonPublicConstructors, the caller must specify the same or a superset — using only NonPublicConstructors will produce IL2091.

Strategy B: Refactor to preserve annotation flow

When annotation flow is broken by boxing (storing Type in object, object[], or untyped collections), refactor to pass the Type directly:

// BROKEN: Type boxed into object[], annotation lost
void Process(object[] args) {
    Type t = (Type)args[0];  // IL2072: annotation lost through boxing
    Evaluate(t, ...);
}

// FIXED: Pass Type as a separate, annotated parameter
void Process(
    object[] args,
    [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type calleeType,
    ...) {
    Evaluate(calleeType, ...);  // annotation flows cleanly
}

Common patterns that break flow and how to fix them:

  • object[] parameter bags: Extract the Type into a dedicated annotated parameter
  • Dictionary/List storage: Use a typed field with annotation instead
  • Interface indirection: Add annotation to the interface method's parameter
  • Property with boxing getter: Annotate the property's return type
Strategy C: Source-generated JSON serialization (batch fix)

When most warnings are IL2026/IL3050 from JsonSerializer.Serialize/Deserialize, this is a single mechanical fix applied in bulk:

  1. Collect affected types — grep for all JsonSerializer.Serialize and JsonSerializer.Deserialize call sites. Extract the type being serialized (the <T> in Deserialize<T>, or the runtime type of the object in Serialize).
  2. Create one JsonSerializerContext with [JsonSerializable] for every type found. Skip types from external packages (e.g., ResponseError from Azure.Core) — they won't source-generate for types you don't own. Handle external types separately via Gotcha #1 below.
[JsonSerializerContext]
[JsonSerializable(typeof(ManagedServiceIdentity))]
[JsonSerializable(typeof(SystemData))]
// ... one attribute per type YOU OWN
// Do NOT add types from external packages (e.g., ResponseError)
internal partial class MyProjectJsonContext : JsonSerializerContext { }
  1. Batch-update all call sites — do not read each file individually. Apply the pattern mechanically: Find and update all call sites in one pass: # Find all files with JsonSerializer calls grep -rl 'JsonSerializer\.\(Serialize\|Deserialize\)' src/ --include='*.cs' Then use sequential edit calls to apply the same transformation to every matching file. Do not use sed for C# code — generics like Deserialize<T>() have angle brackets and nested parentheses that sed will mangle.

- JsonSerializer.Serialize(obj) → JsonSerializer.Serialize(obj, MyProjectJsonContext.Default.TypeName) - JsonSerializer.Deserialize<T>(json) → JsonSerializer.Deserialize(json, MyProjectJsonContext.Default.TypeName)

  1. Build once to verify. Remaining warnings will be non-serialization issues — handle those with Strategies A–B or D.
Strategy D: [RequiresUnreferencedCode] (last resort)

When a method fundamentally requires arbitrary reflection that cannot be statically described:

[RequiresUnreferencedCode("Loads plugins by name using Assembly.Load")]
public void LoadPlugin(string assemblyName) {
    var asm = Assembly.Load(assemblyName);
    // ...
}

This propagates to callers — they must also be annotated with [RequiresUnreferencedCode]. Use sparingly; it marks the entire call chain as trim-incompatible.

Step 5: Rebuild and repeat

After each small batch of fixes (5-10 warnings), rebuild with --no-incremental and check for new warnings. Do not attempt to fix all warnings before rebuilding — frequent rebuilds catch mistakes early and reveal cascading warnings. Fixes cascade — annotating an inner method may surface warnings in its callers. Repeat until 0 Warning(s).

Step 6: Validate all TFMs

Build all target frameworks to ensure:

  • 0 IL warnings on net8.0+ TFMs
  • No NETSDK1210 warnings (the IsAotCompatible condition handles this)
  • Clean builds on older TFMs (netstandard2.0, net472, etc.)
dotnet build <project.csproj>  # builds all TFMs

Stop Signals

  • Do not analyze more than 2-3 representative files per warning pattern. After identifying the fix for a pattern, apply it to all matching files without reading each one first.
  • Start fixing after one build. Do not do a second analysis pass — begin implementing fixes for the most common warning pattern immediately after Step 3 triage.
  • Stop after achieving 0 IL warnings for net8.0+ TFMs. Don't optimize or refactor already-clean annotations.
  • If a warning requires architectural refactoring beyond annotation flow fixes (e.g., replacing an entire serialization layer), document it and stop — don't rewrite large subsystems.
  • Limit to 3 build-fix iterations per warning. If annotation flow doesn't resolve it after 3 attempts, escalate to [RequiresUnreferencedCode].
  • Don't chase warnings in third-party dependencies you can't modify. Note them and move on.
  • If the user asked a scoped question (e.g., "fix warnings in this file"), don't expand to the entire project.

Polyfills for Older TFMs

For multi-targeting projects that include netstandard2.0 or net472, you need polyfills for DynamicallyAccessedMembersAttribute and related types. See references/polyfills.md.

Common Gotchas

  1. External types without AOT-safe serialization: When a type comes from a dependency you can't modify (e.g., ResponseError from Azure.Core) and it lacks a source-generated serializer, Options.GetConverter<T>() is reflection-based and will produce IL warnings. First check if the type implements IJsonModel<T> (common in Azure SDK) — if so, bypass JsonSerializer entirely:
// Before (IL2026 — JsonSerializer uses reflection):
JsonSerializer.Serialize(writer, errorValue);

// After (AOT-safe — uses IJsonModel directly):
((IJsonModel<ResponseError>)errorValue).Write(writer, ModelReaderWriterOptions.Json);

// For deserialization:
var error = ((IJsonModel<ResponseError>)new ResponseError()).Create(ref reader, ModelReaderWriterOptions.Json);

Do not add the external type to your JsonSerializerContext — it won't source-generate for types you don't own. If the type doesn't implement IJsonModel<T>, write a custom JsonConverter<T> with manual Utf8JsonReader/Utf8JsonWriter logic and register it via [JsonSourceGenerationOptions] on your context.

  1. Serialization libraries: Most reflection-based serializers (e.g., Newtonsoft.Json, XmlSerializer) are not AOT-compatible. Migrate to a source-generation-based serializer such as System.Text.Json with a JsonSerializerContext. If migration is not feasible, mark the serialization call site with [RequiresUnreferencedCode].
  2. Shared projects / projitems: When source is shared between multiple projects via <Import>, annotations added to shared code affect ALL consuming projects. Verify that all consumers still build cleanly.

References

Limitations Conceptual: Understanding trimming How-to: trim compat

Checklist

  • Added <IsAotCompatible> with TFM condition to.csproj
  • Built with AOT analyzers enabled (net8.0+ TFM)
  • Fixed all IL warnings via annotations or refactoring
  • No #pragma warning disable or [UnconditionalSuppressMessage] used for any IL warning
  • Polyfills present for older TFMs if needed
  • All target frameworks build with 0 warnings
  • Verified shared/linked source doesn't break sibling projects

平台分布

Codex

34.79%
按下载量换算637

Claude

31.78%
按下载量换算582

Cursor

17.9%
按下载量换算328

Gemini CLI

10.52%
按下载量换算193

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills