SuperAPI AI 工具集

dotnet10-pack-tool

部署与运维

查看项目

更新于 10-15 23:58

技能介绍

用途:指导创建 .NET 10 混合工具包,在选定平台上使用 Native AOT 获得高性能,同时用 CoreCLR 回退保证通用兼容性。触发场景包括“pack .NET tool”“dotnet pack AOT”“Native AOT tool”“hybrid .NET tool”“ToolPackageRuntimeIdentifiers”“.NET 10 tool packaging”“cross-platform .NET tool with AOT”。

主要能力:在 .csproj 中配置 ToolPackageRuntimeIdentifiers 与 PublishAot=true;生成指针包(元包);为每个目标 RID 构建 Native AOT 包;用 -r any 创建 CoreCLR 回退;校验包结构。

使用方式:先在 .csproj 设置 PackAsTool、ToolCommandName、ToolPackageRuntimeIdentifiers(如 any;osx-arm64;linux-arm64;linux-x64)和 PublishAot=true,并可加 InvariantGlobalization、OptimizationPreference、StripSymbols 等 AOT 优化。然后执行 dotnet pack -o ./packages 生成指针包;在各平台或容器中执行 dotnet pack -r osx-arm64、-r linux-arm64、-r linux-x64 构建 AOT 包;最后执行 dotnet pack -r any -p:PublishAot=false 生成 CoreCLR 回退。安装运行:dotnet tool install -g your-tool-name,再运行 your-tool-name,会自动选择平台最佳包。

关键概念:指针包是引用各 RID 包的元包;ToolPackageRuntimeIdentifiers 列出 RID 并创建指针结构(不自动构建);-r any 为未列出平台提供 CoreCLR 回退;-p:PublishAot=false 关闭 AOT。该模式可行的原因是 PublishAot=true 会禁用自动 RID 包生成(AOT 无法跨操作系统交叉编译),需手动按 RID 构建。

要求:安装 .NET 10 SDK;跨平台 Linux 构建需 Docker;AOT 兼容容器为 mcr.microsoft.com/dotnet/sdk:10.0-noble-aot。更多构建脚本、容器构建、CI/CD 模式见 reference.md,示例与排错见 examples.md。