dotnet10-pack-tool
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese.NET 10 Hybrid Pack Tool
.NET 10 混合工具包
Purpose
用途
Guides you through creating hybrid .NET 10 tool packages that combine Native AOT for maximum performance on select platforms with CoreCLR fallback for universal compatibility.
指导你创建混合.NET 10工具包,该工具包结合了Native AOT以在选定平台上实现最高性能,同时通过CoreCLR回退确保通用兼容性。
When I Activate
激活场景
I automatically load when you mention:
- "pack .NET tool" or "dotnet pack AOT"
- "Native AOT tool" or "hybrid .NET tool"
- "ToolPackageRuntimeIdentifiers"
- ".NET 10 tool packaging"
- "cross-platform .NET tool with AOT"
当你提及以下内容时,我会自动加载:
- “pack .NET tool” 或 “dotnet pack AOT”
- “Native AOT tool” 或 “hybrid .NET tool”
- “ToolPackageRuntimeIdentifiers”
- “.NET 10 tool packaging”
- “cross-platform .NET tool with AOT”
What I Do
功能说明
- Configure your .csproj with and
ToolPackageRuntimeIdentifiersPublishAot=true - Generate the pointer package (metapackage)
- Build Native AOT packages for each target RID
- Create CoreCLR fallback with
-r any - Validate package structure
- 为你的.csproj配置和
ToolPackageRuntimeIdentifiersPublishAot=true - 生成指针包(元包)
- 为每个目标RID构建Native AOT包
- 使用创建CoreCLR回退包
-r any - 验证包结构
Quick Start
快速开始
Step 1: Configure .csproj
步骤1:配置.csproj
xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Package as .NET Tool -->
<PackAsTool>true</PackAsTool>
<ToolCommandName>your-tool-name</ToolCommandName>
<!-- RIDs: CoreCLR fallback + Native AOT targets -->
<ToolPackageRuntimeIdentifiers>any;osx-arm64;linux-arm64;linux-x64</ToolPackageRuntimeIdentifiers>
<!-- Enable Native AOT -->
<PublishAot>true</PublishAot>
</PropertyGroup>
<!-- Native AOT optimizations -->
<PropertyGroup Condition="'$(PublishAot)' == 'true'">
<InvariantGlobalization>true</InvariantGlobalization>
<OptimizationPreference>Size</OptimizationPreference>
<StripSymbols>true</StripSymbols>
</PropertyGroup>
</Project>xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<!-- 打包为.NET工具 -->
<PackAsTool>true</PackAsTool>
<ToolCommandName>your-tool-name</ToolCommandName>
<!-- RIDs:CoreCLR回退 + Native AOT目标平台 -->
<ToolPackageRuntimeIdentifiers>any;osx-arm64;linux-arm64;linux-x64</ToolPackageRuntimeIdentifiers>
<!-- 启用Native AOT -->
<PublishAot>true</PublishAot>
</PropertyGroup>
<!-- Native AOT优化配置 -->
<PropertyGroup Condition="'$(PublishAot)' == 'true'">
<InvariantGlobalization>true</InvariantGlobalization>
<OptimizationPreference>Size</OptimizationPreference>
<StripSymbols>true</StripSymbols>
</PropertyGroup>
</Project>Step 2: Build Packages
步骤2:构建包
bash
undefinedbash
undefined1. Create pointer package (no binaries, just metadata)
1. 创建指针包(无二进制文件,仅包含元数据)
dotnet pack -o ./packages
dotnet pack -o ./packages
2. Build Native AOT for each target platform
2. 为每个目标平台构建Native AOT包
dotnet pack -r osx-arm64 -o ./packages # On macOS
dotnet pack -r linux-arm64 -o ./packages # On Linux ARM or container
dotnet pack -r linux-x64 -o ./packages # On Linux x64 or container
dotnet pack -r osx-arm64 -o ./packages # 在macOS上执行
dotnet pack -r linux-arm64 -o ./packages # 在Linux ARM或容器中执行
dotnet pack -r linux-x64 -o ./packages # 在Linux x64或容器中执行
3. Create CoreCLR fallback for all other platforms
3. 为所有其他平台创建CoreCLR回退包
dotnet pack -r any -p:PublishAot=false -o ./packages
undefineddotnet pack -r any -p:PublishAot=false -o ./packages
undefinedStep 3: Install & Run
步骤3:安装与运行
bash
dotnet tool install -g your-tool-name
your-tool-name # Auto-selects best package for platformbash
undefinedKey Concepts
全局安装你的工具
| Concept | Description |
|---|---|
| Pointer Package | Metapackage that references RID-specific packages |
| ToolPackageRuntimeIdentifiers | Lists RIDs, creates pointer structure (no auto-build) |
| CoreCLR fallback for unlisted platforms |
| Disables AOT for CoreCLR fallback |
dotnet tool install -g your-tool-name
your-tool-name # 自动为当前平台选择最佳包
undefinedWhy This Pattern Works
核心概念
- disables automatic RID package generation (AOT can't cross-compile OSes)
PublishAot=true - creates the pointer package structure
ToolPackageRuntimeIdentifiers - Manual builds produce AOT binaries per platform
-r <RID> - creates portable CoreCLR fallback
-r any -p:PublishAot=false
| 概念 | 描述 |
|---|---|
| Pointer Package | 引用特定RID包的元包 |
| ToolPackageRuntimeIdentifiers | 列出RID,创建指针包结构(不会自动构建) |
| 为未列出的平台提供CoreCLR回退 |
| 为CoreCLR回退包禁用AOT |
Documentation
该模式的工作原理
- reference.md: Complete build script, container builds, CI/CD patterns
- examples.md: Real-world examples and troubleshooting
- 会禁用自动RID包生成(AOT无法跨操作系统编译)
PublishAot=true - 创建指针包结构
ToolPackageRuntimeIdentifiers - 手动执行构建可生成每个平台的AOT二进制文件
-r <RID> - 创建可移植的CoreCLR回退包
-r any -p:PublishAot=false
Requirements
文档
- .NET 10 SDK installed
- Docker (for cross-platform Linux builds from macOS/Windows)
- AOT-compatible container:
mcr.microsoft.com/dotnet/sdk:10.0-noble-aot
- reference.md:完整的构建脚本、容器构建、CI/CD模式
- examples.md:实际案例与故障排除
—
要求
—
- 已安装.NET 10 SDK
- Docker(用于从macOS/Windows进行跨平台Linux构建)
- 兼容AOT的容器:
mcr.microsoft.com/dotnet/sdk:10.0-noble-aot