migrate-dotnet10-to-dotnet11
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese.NET 10 → .NET 11 Migration
.NET 10 迁移至 .NET 11
Migrate a .NET 10 project or solution to .NET 11, systematically resolving all breaking changes. The outcome is a project targeting that builds cleanly, passes tests, and accounts for every behavioral, source-incompatible, and binary-incompatible change introduced in .NET 11.
net11.0Note: .NET 11 is currently in preview. This skill covers breaking changes documented through Preview 3.
将.NET 10项目或解决方案迁移至.NET 11,系统性解决所有重大变更问题。最终成果是一个目标框架为的项目,可正常构建、通过测试,并适配.NET 11引入的所有行为变更、源代码不兼容及二进制不兼容问题。
net11.0注意: .NET 11目前处于预览阶段。本技能涵盖预览版3之前已记录的所有重大变更。
When to Use
适用场景
- Upgrading from
TargetFrameworktonet10.0net11.0 - Resolving build errors or new warnings after updating the .NET 11 SDK
- Adapting to behavioral changes in .NET 11 runtime, ASP.NET Core 11, or EF Core 11
- Updating CI/CD pipelines, Dockerfiles, or deployment scripts for .NET 11
- Fixing C# 15 compiler breaking changes after SDK upgrade
- 将从
TargetFramework升级至net10.0net11.0 - 更新.NET 11 SDK后解决构建错误或新出现的警告
- 适配.NET 11运行时、ASP.NET Core 11或EF Core 11的行为变更
- 为.NET 11更新CI/CD流水线、Dockerfile或部署脚本
- SDK升级后修复C# 15编译器的重大变更问题
When Not to Use
不适用场景
- The project already targets and builds cleanly — migration is done
net11.0 - Upgrading from .NET 9 or earlier — address the .NET 9→10 breaking changes first
- Migrating from .NET Framework — that is a separate, larger effort
- Greenfield projects that start on .NET 11 (no migration needed)
- 项目已目标且可正常构建——迁移已完成
net11.0 - 从.NET 9或更早版本升级——需先处理.NET 9→10的重大变更
- 从.NET Framework迁移——这是一项独立且更复杂的工作
- 基于.NET 11的全新项目开发(无需迁移)
Inputs
输入项
| Input | Required | Description |
|---|---|---|
| Project or solution path | Yes | The |
| Build command | No | How to build (e.g., |
| Test command | No | How to run tests (e.g., |
| Project type hints | No | Whether the project uses ASP.NET Core, EF Core, Cosmos DB, etc. Auto-detect from PackageReferences and SDK attributes if not provided |
| 输入项 | 是否必填 | 描述 |
|---|---|---|
| 项目或解决方案路径 | 是 | 待迁移的 |
| 构建命令 | 否 | 构建方式(如 |
| 测试命令 | 否 | 测试运行方式(如 |
| 项目类型提示 | 否 | 项目是否使用ASP.NET Core、EF Core、Cosmos DB等。未提供时通过PackageReferences和SDK属性自动检测 |
Workflow
工作流程
Answer directly from the loaded reference documents for information about .NET 11 breaking changes. You may inspect the local repository (project/solution files, source code, configuration, build/test scripts) as needed to determine which changes apply. Do not fetch web pages or other external sources for breaking change information — the loaded references are the authoritative source. Focus on identifying which breaking changes apply and providing concrete fixes.Commit strategy: Commit at each logical boundary — after updating the TFM (Step 2), after resolving build errors (Step 3), after addressing behavioral changes (Step 4), and after updating infrastructure (Step 5). This keeps each commit focused and reviewable.
关于.NET 11重大变更的信息,请直接从已加载的参考文档中获取。 可根据需要检查本地仓库(项目/解决方案文件、源代码、配置、构建/测试脚本)以确定适用的变更。请勿从网页或其他外部来源获取重大变更信息——已加载的参考文档为权威来源。重点在于识别适用的重大变更并提供具体修复方案。提交策略: 在每个逻辑节点提交代码——更新目标框架(步骤2)后、解决构建错误(步骤3)后、处理行为变更(步骤4)后、更新基础设施(步骤5)后。确保每次提交聚焦明确,便于评审。
Step 1: Assess the project
步骤1:评估项目
- Identify how the project is built and tested. Look for build scripts, /
.slnfiles, or individual.slnxfiles..csproj - Run to confirm the .NET 11 SDK is installed. If it is not, stop and inform the user.
dotnet --version - Determine which technology areas the project uses by examining:
- SDK attribute: → ASP.NET Core;
Microsoft.NET.Sdk.WebwithMicrosoft.NET.Sdk.WindowsDesktopor<UseWPF>→ WPF/WinForms<UseWindowsForms> - PackageReferences: → EF Core;
Microsoft.EntityFrameworkCore.*→ Cosmos DB providerMicrosoft.EntityFrameworkCore.Cosmos - Dockerfile presence → Container changes relevant
- Cryptography API usage → DSA on macOS affected; AIA cert download changes relevant
- Compression API usage → DeflateStream/GZipStream/ZipArchive changes relevant
- TAR API usage → Header checksum validation and HardLink entry changes relevant
- usage with
NamedPipeClientStream→ SYSLIB0063 constructor obsoletion relevantSafePipeHandle - usage → Unhandled exceptions now stop the host
BackgroundService - direct usage → v3 API breaking changes in ASP.NET Core OpenAPI
Microsoft.OpenApi - EF Core SQL Server with Entra ID auth → SqlClient 7.0 auth dependency changes
- NativeAOT native libraries on Unix → Output filename prefix changed
- SDK attribute:
- Record which reference documents are relevant (see the reference loading table in Step 3).
- Do a clean build (or delete
dotnet build --no-incremental/bin) on the currentobjtarget to establish a clean baseline. Record any pre-existing warnings.net10.0
- 确定项目的构建和测试方式。查找构建脚本、/
.sln文件或单个.slnx文件。.csproj - 运行确认已安装.NET 11 SDK。若未安装,停止操作并告知用户。
dotnet --version - 通过以下方式确定项目使用的技术领域:
- SDK属性:→ ASP.NET Core;
Microsoft.NET.Sdk.Web搭配Microsoft.NET.Sdk.WindowsDesktop或<UseWPF>→ WPF/WinForms<UseWindowsForms> - PackageReferences:→ EF Core;
Microsoft.EntityFrameworkCore.*→ Cosmos DB提供程序Microsoft.EntityFrameworkCore.Cosmos - Dockerfile存在性 → 需关注容器相关变更
- 加密API使用情况 → macOS上的DSA受影响;AIA证书下载变更适用
- 压缩API使用情况 → DeflateStream/GZipStream/ZipArchive变更适用
- TAR API使用情况 → 头部校验和验证与HardLink条目变更适用
- 搭配
NamedPipeClientStream使用 → SYSLIB0063构造函数弃用相关SafePipeHandle - 使用情况 → 未处理的异常现在会停止宿主
BackgroundService - 直接使用 → ASP.NET Core OpenAPI中的v3 API重大变更
Microsoft.OpenApi - EF Core SQL Server搭配Entra ID认证 → SqlClient 7.0认证依赖变更
- Unix上的NativeAOT原生库 → 输出文件名前缀已更改
- SDK属性:
- 记录适用的参考文档(见步骤3中的参考加载表)。
- 在当前目标上执行清理构建(
net10.0或删除dotnet build --no-incremental/bin目录),建立干净的基线。记录所有预先存在的警告。obj
Step 2: Update the Target Framework
步骤2:更新目标框架
-
In each(or
.csprojif centralized), change:Directory.Build.propsxml<TargetFramework>net10.0</TargetFramework>to:xml<TargetFramework>net11.0</TargetFramework>For multi-targeted projects, addtonet11.0or replace<TargetFrameworks>.net10.0 -
Update all,
Microsoft.Extensions.*,Microsoft.AspNetCore.*, and other Microsoft package references to their 11.0.x versions. If using Central Package Management (Microsoft.EntityFrameworkCore.*), update versions there.Directory.Packages.props -
Run. Fix any restore errors before continuing.
dotnet restore -
Run. Capture all errors and warnings — these will be addressed in Step 3.
dotnet build
-
在每个(或集中管理的
.csproj)中,将:Directory.Build.propsxml<TargetFramework>net10.0</TargetFramework>修改为:xml<TargetFramework>net11.0</TargetFramework>对于多目标项目,将添加到net11.0中或替换<TargetFrameworks>。net10.0 -
将所有、
Microsoft.Extensions.*、Microsoft.AspNetCore.*及其他Microsoft包引用更新至11.0.x版本。若使用集中包管理(Microsoft.EntityFrameworkCore.*),在该文件中更新版本。Directory.Packages.props -
运行。继续操作前修复所有还原错误。
dotnet restore -
运行。捕获所有错误和警告——这些将在步骤3中处理。
dotnet build
Step 3: Fix source-breaking and compilation changes
步骤3:修复源代码兼容与编译变更
Load reference documents based on the project's technology areas:
| Reference file | When to load |
|---|---|
| Always (C# 15 compiler breaking changes) |
| Always (applies to all .NET 11 projects) |
| Always (SDK and build tooling changes) |
| Project uses ASP.NET Core (OpenAPI, Blazor) |
| Project uses Entity Framework Core |
| Project uses cryptography APIs, mTLS, or targets macOS |
| Deploying to older hardware, embedded devices, or using NativeAOT |
Work through each build error systematically. Common patterns:
-
C# 15 Span collection expression safe-context — Collection expressions of/
Span<T>type now haveReadOnlySpan<T>safe-context. Code assigning span collection expressions to variables in outer scopes will error. Use array type or move the expression to the correct scope.declaration-block -
delegates/local functions need
ref readonly— If synthesizing delegates fromInAttribute-returning methods or usingref readonlylocal functions, ensureref readonlyis available.System.Runtime.InteropServices.InAttribute -
in attributes — Remove
nameof(this.)qualifier; usethis.instead ofnameof(P).nameof(this.P) -
in collection expressions (C# 15) —
with()is now treated as constructor arguments, not a method call. Usewith(...)to call a method named@with(...).with -
Dynamic/
&&with interface operand — Interface types as left operand of||/&&with||right operand now errors at compile time. Cast to concrete type ordynamic.dynamic -
EF Core Cosmos sync I/O removal —,
ToList(), etc. on Cosmos provider always throw. Convert to async equivalents.SaveChanges() -
SYSLIB0063:
NamedPipeClientStreamparameter obsoleted — The constructor overload takingisConnectedis obsoleted. Remove thebool isConnectedargument and use the new 3-parameter constructor. Projects withisConnectedwill fail to build.TreatWarningsAsErrors -
switch-expression-arm parsing —
whenis now parsed as a constant pattern with a(X.Y) whenclause instead of a cast expression, which can cause existing code to fail to compile or change meaning. Review switch expressions usingwhenand adjust syntax as needed.when -
Microsoft.OpenApi v3 breaking changes —now depends on
Microsoft.AspNetCore.OpenApi3.x. Code usingMicrosoft.OpenApitypes directly (Microsoft.OpenApi,OpenApiDocument, etc.) will have compile errors. Follow the v3 upgrade guide.OpenApiSchema -
EF Core Design package no longer transitive —and
Microsoft.EntityFrameworkCore.Toolsno longer depend on.Tasks. Add an explicit.Designif needed.PackageReference -
EFOptimizeContext MSBuild property removed — Replace withand
<EFScaffoldModelStage>.<EFPrecompileQueriesStage>
根据项目的技术领域加载参考文档:
| 参考文件 | 加载场景 |
|---|---|
| 始终加载(C# 15编译器重大变更) |
| 始终加载(适用于所有.NET 11项目) |
| 始终加载(SDK与构建工具变更) |
| 项目使用ASP.NET Core(OpenAPI、Blazor) |
| 项目使用Entity Framework Core |
| 项目使用加密API、mTLS或目标平台为macOS |
| 部署至老旧硬件、嵌入式设备或使用NativeAOT |
系统性处理每个构建错误。常见模式:
-
C# 15 Span集合表达式安全上下文 ——/
Span<T>类型的集合表达式现在具有ReadOnlySpan<T>安全上下文。将span集合表达式赋值给外部作用域变量的代码会报错。使用数组类型或将表达式移至正确作用域。declaration-block -
委托/局部函数需要
ref readonly—— 若从返回InAttribute的方法合成委托或使用ref readonly局部函数,确保ref readonly可用。System.Runtime.InteropServices.InAttribute -
属性中的—— 移除
nameof(this.)限定符;使用this.替代nameof(P)。nameof(this.P) -
集合表达式中的(C# 15) ——
with()现在被视为构造函数参数,而非方法调用。调用名为with(...)的方法时使用with。@with(...) -
动态/
&&搭配接口操作数 —— 接口类型作为||/&&的左操作数且右侧为||时,现在会在编译时报错。转换为具体类型或dynamic。dynamic -
EF Core Cosmos同步I/O移除 —— Cosmos提供程序上的、
ToList()等方法始终会抛出异常。转换为异步等效方法。SaveChanges() -
SYSLIB0063:的
NamedPipeClientStream参数已弃用 —— 接受isConnected参数的构造函数重载已被弃用。移除bool isConnected参数并使用新的3参数构造函数。开启isConnected的项目将无法构建。TreatWarningsAsErrors -
开关表达式分支解析 ——
when现在被解析为带有(X.Y) when子句的常量模式,而非强制转换表达式,这可能导致现有代码无法编译或改变语义。检查使用when的开关表达式并根据需要调整语法。when -
Microsoft.OpenApi v3重大变更 ——现在依赖
Microsoft.AspNetCore.OpenApi3.x。直接使用Microsoft.OpenApi类型(Microsoft.OpenApi、OpenApiDocument等)的代码会出现编译错误。遵循v3升级指南。OpenApiSchema -
EF Core Design包不再作为传递依赖 ——和
Microsoft.EntityFrameworkCore.Tools不再依赖.Tasks。若需要,添加显式的.Design。PackageReference -
EFOptimizeContext MSBuild属性已移除 —— 替换为和
<EFScaffoldModelStage>。<EFPrecompileQueriesStage>
Step 4: Address behavioral changes
步骤4:处理行为变更
These changes compile successfully but alter runtime behavior. Review each one and determine impact:
-
DeflateStream/GZipStream empty payload — Now writes headers and footers even for empty payloads. If your code checks for zero-length output, update the check.
-
MemoryStream maximum capacity — Maximum capacity updated and exception behavior changed. Review code that creates large MemoryStreams or relies on specific exception types.
-
TAR header checksum validation — TAR-reading APIs now verify checksums. Corrupted or hand-crafted TAR files may now fail to read.
-
ZipArchive.CreateAsync eager loading —eagerly loads entries. May affect memory usage for large archives.
ZipArchive.CreateAsync -
Environment.TickCount consistency — Made consistent with Windows timeout behavior. Code relying on specific tick count behavior may need adjustment.
-
DSA removed from macOS — DSA cryptographic operations throw on macOS. Use a different algorithm (RSA, ECDSA).
-
Japanese Calendar minimum date — Minimum supported date corrected. Code using very early Japanese Calendar dates may be affected.
-
Minimum hardware requirements — x86/x64 baseline moved to; Windows Arm64 requires
x86-64-v2. Verify deployment targets meet requirements.LSE -
Mono launch target for .NET Framework — No longer set automatically. If using Mono for .NET Framework apps on Linux, specify explicitly.
-
Unhandled BackgroundService exceptions stop the host — Exceptions fromnow propagate and crash the host. Add try/catch in background services that should not bring down the application.
ExecuteAsync() -
ZipArchive CRC32 validation — ZIP reads now validate CRC32 checksums. Corrupt or truncated archives that previously succeeded will now throw.
InvalidDataException -
TarWriter emits HardLink entries — Hard-linked files are now written asentries instead of duplicated data. Consumers of .NET-produced tar archives must handle
HardLinkentries.HardLink -
AIA certificate downloads disabled — Server-side client-certificate validation no longer downloads intermediate CAs via AIA by default. Pre-install the full chain or have clients send intermediates.
-
Blazor Virtualize OverscanCount default changed — Defaultchanged from 3 to 15. Set explicitly if performance-sensitive.
OverscanCount -
Microsoft.Data.SqlClient 7.0 — Entra ID auth separated — Azure/Entra ID authentication dependencies removed from the core SqlClient package. Addif using Entra ID auth.
Microsoft.Data.SqlClient.Extensions.Azure -
SqlVector<T> excluded from SELECT — Vector properties are no longer auto-loaded. Use explicit projections to include vector values.
-
SQLitePCLRaw encryption bundles removed —and other encryption bundle packages removed in SQLitePCLRaw 3.0.
bundle_e_sqlcipher -
NativeAOT Unix native libraryprefix — Output filenames now include
libprefix on Linux/macOS (e.g.,lib).libMyLib.so
这些变更可成功编译,但会改变运行时行为。逐一检查并确定影响:
-
DeflateStream/GZipStream空负载 —— 即使是空负载,现在也会写入头部和尾部。若代码检查零长度输出,更新检查逻辑。
-
MemoryStream最大容量 —— 最大容量已更新,异常行为已改变。检查创建大型MemoryStream或依赖特定异常类型的代码。
-
TAR头部校验和验证 —— TAR读取API现在会验证校验和。损坏或手工制作的TAR文件现在可能无法读取。
-
ZipArchive.CreateAsync预加载 ——会预加载条目。可能影响大型归档文件的内存使用。
ZipArchive.CreateAsync -
Environment.TickCount一致性 —— 已与Windows超时行为保持一致。依赖特定TickCount行为的代码可能需要调整。
-
macOS上移除DSA —— macOS上的DSA加密操作会抛出异常。使用其他算法(RSA、ECDSA)。
-
日本历法最小日期 —— 修正了支持的最小日期。使用极早日本历法日期的代码可能受影响。
-
最低硬件要求 —— x86/x64基准已升级至;Windows Arm64需要
x86-64-v2。验证部署目标满足要求。LSE -
.NET Framework的Mono启动目标 —— 不再自动设置。若在Linux上使用Mono运行.NET Framework应用,需显式指定。
-
未处理的BackgroundService异常会停止宿主 ——中的异常现在会传播并导致宿主崩溃。在不应导致应用崩溃的后台服务中添加try/catch。
ExecuteAsync() -
ZipArchive CRC32验证 —— ZIP读取现在会验证CRC32校验和。之前可成功读取的损坏或截断归档文件现在会抛出。
InvalidDataException -
TarWriter输出HardLink条目 —— 硬链接文件现在会作为条目写入,而非重复数据。使用.NET生成的tar归档文件的消费者必须处理
HardLink条目。HardLink -
AIA证书下载已禁用 —— 服务器端客户端证书验证默认不再通过AIA下载中间CA。预安装完整证书链或让客户端发送中间证书。
-
Blazor Virtualize OverscanCount默认值变更 —— 默认从3变更为15。若对性能敏感,需显式设置。
OverscanCount -
Microsoft.Data.SqlClient 7.0 —— Entra ID认证分离 —— Azure/Entra ID认证依赖已从核心SqlClient包中移除。若使用Entra ID认证,添加。
Microsoft.Data.SqlClient.Extensions.Azure -
SqlVector<T>被排除在SELECT之外 —— 向量属性不再自动加载。使用显式投影来包含向量值。
-
SQLitePCLRaw加密包已移除 —— SQLitePCLRaw 3.0中已移除及其他加密包。
bundle_e_sqlcipher -
NativeAOT Unix原生库的前缀 —— Linux/macOS上的输出文件名现在包含
lib前缀(如lib)。libMyLib.so
Step 5: Update infrastructure
步骤5:更新基础设施
-
Dockerfiles: Update base images from 10.0 to 11.0:dockerfile
# Before FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build FROM mcr.microsoft.com/dotnet/aspnet:10.0 # After FROM mcr.microsoft.com/dotnet/sdk:11.0 AS build FROM mcr.microsoft.com/dotnet/aspnet:11.0 -
CI/CD pipelines: Update SDK version references. If using, update the
global.jsonin your existing file while preserving other keys (such assdk.versionand test configuration):rollForwarddiff{ "sdk": { - "version": "10.0.100", - "rollForward": "latestFeature" + "version": "11.0.100-preview.3", + "rollForward": "latestFeature" }, "otherSettings": { "...": "..." } } -
Hardware deployment targets: Verify all deployment targets meet the updated minimum hardware requirements (x86-64-v2 for x86/x64, LSE for Windows Arm64).
-
Dockerfile:将基础镜像从10.0更新至11.0:dockerfile
# 之前 FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build FROM mcr.microsoft.com/dotnet/aspnet:10.0 # 之后 FROM mcr.microsoft.com/dotnet/sdk:11.0 AS build FROM mcr.microsoft.com/dotnet/aspnet:11.0 -
CI/CD流水线:更新SDK版本引用。若使用,更新现有文件中的
global.json,同时保留其他键(如sdk.version和测试配置):rollForwarddiff{ "sdk": { - "version": "10.0.100", - "rollForward": "latestFeature" + "version": "11.0.100-preview.3", + "rollForward": "latestFeature" }, "otherSettings": { "...": "..." } } -
硬件部署目标:验证所有部署目标满足更新后的最低硬件要求(x86/x64为x86-64-v2,Windows Arm64为LSE)。
Step 6: Verify
步骤6:验证
- Run a full clean build:
dotnet build --no-incremental - Run all tests:
dotnet test - If the application is containerized, build and test the container image
- Smoke-test the application, paying special attention to:
- Compression behavior with empty streams
- TAR file reading (checksum validation and HardLink entries)
- EF Core Cosmos DB operations (must be async)
- DSA usage on macOS
- Memory-intensive MemoryStream usage
- Span collection expression assignments
- BackgroundService exception handling
- mTLS / client certificate chain validation
- EF Core SQL Server with Entra ID authentication
- NativeAOT output filenames on Unix
- Review the diff and ensure no unintended behavioral changes were introduced
- 执行完整清理构建:
dotnet build --no-incremental - 运行所有测试:
dotnet test - 若应用已容器化,构建并测试容器镜像
- 对应用进行冒烟测试,重点关注:
- 空流的压缩行为
- TAR文件读取(校验和验证与HardLink条目)
- EF Core Cosmos DB操作(必须为异步)
- macOS上的DSA使用
- 内存密集型MemoryStream使用
- Span集合表达式赋值
- BackgroundService异常处理
- mTLS / 客户端证书链验证
- EF Core SQL Server搭配Entra ID认证
- Unix上的NativeAOT输出文件名
- 检查差异,确保未引入意外的行为变更
Reference Documents
参考文档
The folder contains detailed breaking change information organized by technology area. Load only the references relevant to the project being migrated:
references/| Reference file | When to load |
|---|---|
| Always (C# 15 compiler breaking changes) |
| Always (applies to all .NET 11 projects) |
| Always (SDK and build tooling changes) |
| Project uses ASP.NET Core (OpenAPI, Blazor) |
| Project uses Entity Framework Core |
| Project uses cryptography APIs, mTLS, or targets macOS |
| Deploying to older hardware, embedded devices, or using NativeAOT |
references/| 参考文件 | 加载场景 |
|---|---|
| 始终加载(C# 15编译器重大变更) |
| 始终加载(适用于所有.NET 11项目) |
| 始终加载(SDK与构建工具变更) |
| 项目使用ASP.NET Core(OpenAPI、Blazor) |
| 项目使用Entity Framework Core |
| 项目使用加密API、mTLS或目标平台为macOS |
| 部署至老旧硬件、嵌入式设备或使用NativeAOT |