migrate-dotnet8-to-dotnet9

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

.NET 8 → .NET 9 Migration

.NET 8 迁移至 .NET 9

Migrate a .NET 8 project or solution to .NET 9, systematically resolving all breaking changes. The outcome is a project targeting
net9.0
that builds cleanly, passes tests, and accounts for every behavioral, source-incompatible, and binary-incompatible change introduced in the .NET 9 release.
将 .NET 8 项目或解决方案迁移至 .NET 9,系统地解决所有重大变更问题。最终成果是一个以
net9.0
为目标框架的项目,可正常构建、通过测试,并适配 .NET 9 版本中引入的所有行为、源代码不兼容和二进制不兼容变更。

When to Use

适用场景

  • Upgrading
    TargetFramework
    from
    net8.0
    to
    net9.0
  • Resolving build errors or new warnings after updating the .NET 9 SDK
  • Adapting to behavioral changes in .NET 9 runtime, ASP.NET Core 9, or EF Core 9
  • Replacing
    BinaryFormatter
    usage (now always throws at runtime)
  • Updating CI/CD pipelines, Dockerfiles, or deployment scripts for .NET 9
  • TargetFramework
    net8.0
    升级至
    net9.0
  • 更新 .NET 9 SDK 后解决构建错误或新警告
  • 适配 .NET 9 运行时、ASP.NET Core 9 或 EF Core 9 中的行为变更
  • 替换
    BinaryFormatter
    的使用(现在在运行时始终会抛出异常)
  • 为 .NET 9 更新 CI/CD 流水线、Dockerfile 或部署脚本

When Not to Use

不适用场景

  • The project already targets
    net9.0
    and builds cleanly — migration is done. If the goal is to reach
    net10.0
    , use the
    migrate-dotnet9-to-dotnet10
    skill as the next step.
  • Upgrading from .NET 7 or earlier — address the prior version breaking changes first
  • Migrating from .NET Framework — that is a separate, larger effort
  • Greenfield projects that start on .NET 9 (no migration needed)
  • 项目已以
    net9.0
    为目标框架且可正常构建——迁移已完成。如果目标是升级至
    net10.0
    ,下一步请使用
    migrate-dotnet9-to-dotnet10
    技能。
  • 从 .NET 7 或更早版本升级——请先处理旧版本的重大变更问题
  • 从 .NET Framework 迁移——这是一项独立且更复杂的工作
  • 全新的 .NET 9 项目(无需迁移)

Inputs

输入项

InputRequiredDescription
Project or solution pathYesThe
.csproj
,
.sln
, or
.slnx
entry point to migrate
Build commandNoHow to build (e.g.,
dotnet build
, a repo build script). Auto-detect if not provided
Test commandNoHow to run tests (e.g.,
dotnet test
). Auto-detect if not provided
Project type hintsNoWhether the project uses ASP.NET Core, EF Core, WinForms, WPF, containers, etc. Auto-detect from PackageReferences and SDK attributes if not provided
输入项是否必填描述
项目或解决方案路径要迁移的
.csproj
.sln
.slnx
入口文件
构建命令构建方式(例如:
dotnet build
、仓库构建脚本)。未提供时将自动检测
测试命令运行测试的方式(例如:
dotnet test
)。未提供时将自动检测
项目类型提示项目是否使用 ASP.NET Core、EF Core、WinForms、WPF、容器等。未提供时将通过 PackageReferences 和 SDK 属性自动检测

Workflow

工作流程

Answer directly from the loaded reference documents. Do not search the filesystem or fetch web pages for breaking change information — the references contain the authoritative details. 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.
直接从加载的参考文档中获取答案。请勿在文件系统中搜索或从网页获取重大变更信息——参考文档包含权威细节。重点识别哪些重大变更适用并提供具体修复方案。
提交策略:在每个逻辑节点提交代码——更新 TFM(步骤2)后、解决构建错误(步骤3)后、处理行为变更(步骤4)后、更新基础设施(步骤5)后。这样可使每次提交的内容聚焦且便于评审。

Step 1: Assess the project

步骤1:评估项目

  1. Identify how the project is built and tested. Look for build scripts,
    .sln
    /
    .slnx
    files, or individual
    .csproj
    files.
  2. Run
    dotnet --version
    to confirm the .NET 9 SDK is installed. If it is not, stop and inform the user.
  3. Determine which technology areas the project uses by examining:
    • SDK attribute:
      Microsoft.NET.Sdk.Web
      → ASP.NET Core;
      Microsoft.NET.Sdk.WindowsDesktop
      with
      <UseWPF>
      or
      <UseWindowsForms>
      → WPF/WinForms
    • PackageReferences:
      Microsoft.EntityFrameworkCore.*
      → EF Core;
      Microsoft.Extensions.Http
      → HttpClientFactory
    • Dockerfile presence → Container changes relevant
    • P/Invoke or native interop usage → Interop changes relevant
    • BinaryFormatter
      usage
      → Serialization migration needed
    • System.Text.Json
      usage
      → Serialization changes relevant
    • X509Certificate constructors → Cryptography changes relevant
  4. Record which reference documents are relevant (see the reference loading table in Step 3).
  5. Do a clean build (
    dotnet build --no-incremental
    or delete
    bin
    /
    obj
    ) on the current
    net8.0
    target to establish a clean baseline. Record any pre-existing warnings.
  1. 确定项目的构建和测试方式。查找构建脚本、
    .sln
    /
    .slnx
    文件或单个
    .csproj
    文件。
  2. 运行
    dotnet --version
    确认已安装 .NET 9 SDK。如果未安装,请停止操作并告知用户。
  3. 通过检查以下内容确定项目使用的技术领域:
    • SDK 属性
      Microsoft.NET.Sdk.Web
      → ASP.NET Core;
      Microsoft.NET.Sdk.WindowsDesktop
      搭配
      <UseWPF>
      <UseWindowsForms>
      → WPF/WinForms
    • PackageReferences
      Microsoft.EntityFrameworkCore.*
      → EF Core;
      Microsoft.Extensions.Http
      → HttpClientFactory
    • Dockerfile 存在性 → 需关注容器相关变更
    • P/Invoke 或原生互操作使用情况 → 需关注互操作变更
    • BinaryFormatter
      使用情况
      → 需要进行序列化迁移
    • System.Text.Json
      使用情况
      → 需关注序列化变更
    • X509Certificate 构造函数 → 需关注加密变更
  4. 记录相关的参考文档(请参阅步骤3中的参考文档加载表)。
  5. 在当前
    net8.0
    目标框架上执行清理构建
    dotnet build --no-incremental
    或删除
    bin
    /
    obj
    目录),建立干净的基线。记录所有预先存在的警告。

Step 2: Update the Target Framework

步骤2:更新目标框架

  1. In each
    .csproj
    (or
    Directory.Build.props
    if centralized), change:
    xml
    <TargetFramework>net8.0</TargetFramework>
    to:
    xml
    <TargetFramework>net9.0</TargetFramework>
    For multi-targeted projects, add
    net9.0
    to
    <TargetFrameworks>
    or replace
    net8.0
    .
  2. Update all
    Microsoft.Extensions.*
    ,
    Microsoft.AspNetCore.*
    ,
    Microsoft.EntityFrameworkCore.*
    , and other Microsoft package references to their 9.0.x versions. If using Central Package Management (
    Directory.Packages.props
    ), update versions there.
  3. Run
    dotnet restore
    . Watch for:
    • Version requirements: .NET 9 SDK requires Visual Studio 17.12+ to target
      net9.0
      (17.11 for
      net8.0
      and earlier).
    • New warnings for .NET Standard 1.x and .NET 7 targets — consider updating or removing outdated target frameworks.
  4. Run a clean build. Collect all errors and new warnings. These will be addressed in Step 3.
  1. 在每个
    .csproj
    文件(如果是集中管理则为
    Directory.Build.props
    )中,将:
    xml
    <TargetFramework>net8.0</TargetFramework>
    修改为:
    xml
    <TargetFramework>net9.0</TargetFramework>
    对于多目标框架项目,将
    net9.0
    添加至
    <TargetFrameworks>
    或替换
    net8.0
  2. 将所有
    Microsoft.Extensions.*
    Microsoft.AspNetCore.*
    Microsoft.EntityFrameworkCore.*
    及其他 Microsoft 包引用更新至 9.0.x 版本。如果使用集中包管理(
    Directory.Packages.props
    ),请在该文件中更新版本。
  3. 运行
    dotnet restore
    。注意:
    • 版本要求:.NET 9 SDK 需要 Visual Studio 17.12+ 才能以
      net9.0
      为目标框架(
      net8.0
      及更早版本需要 17.11)。
    • 针对 .NET Standard 1.x 和 .NET 7 目标框架的新警告——考虑更新或移除过时的目标框架。
  4. 执行清理构建。收集所有错误和新警告,这些将在步骤3中处理。

Step 3: Resolve build errors and source-incompatible changes

步骤3:解决构建错误和源代码不兼容变更

Work through compilation errors and new warnings systematically. Load the appropriate reference documents based on the project type:
If the project uses…Load reference
Any .NET 9 project
references/csharp-compiler-dotnet8to9.md
Any .NET 9 project
references/core-libraries-dotnet8to9.md
Any .NET 9 project
references/sdk-msbuild-dotnet8to9.md
ASP.NET Core
references/aspnet-core-dotnet8to9.md
Entity Framework Core
references/efcore-dotnet8to9.md
Cryptography APIs
references/cryptography-dotnet8to9.md
System.Text.Json, HttpClient, networking
references/serialization-networking-dotnet8to9.md
Windows Forms or WPF
references/winforms-wpf-dotnet8to9.md
Docker containers, native interop
references/containers-interop-dotnet8to9.md
Runtime configuration, deployment
references/deployment-runtime-dotnet8to9.md
Common source-incompatible changes to check for:
  1. params
    span overload resolution
    — New
    params ReadOnlySpan<T>
    overloads on
    String.Join
    ,
    String.Concat
    ,
    Path.Combine
    ,
    Task.WhenAll
    , and many more now bind preferentially. Code calling these methods inside
    Expression
    lambdas will fail (CS8640/CS9226). See
    references/core-libraries-dotnet8to9.md
    .
  2. StringValues
    ambiguous overload
    — The
    params Span<T>
    feature creates ambiguity with
    StringValues
    implicit operators on methods like
    String.Concat
    ,
    String.Join
    ,
    Path.Combine
    . Fix by explicitly casting arguments. See
    references/core-libraries-dotnet8to9.md
    .
  3. New obsoletion warnings (SYSLIB0054–SYSLIB0057):
    • SYSLIB0054
      : Replace
      Thread.VolatileRead
      /
      VolatileWrite
      with
      Volatile.Read
      /
      Volatile.Write
    • SYSLIB0057
      : Replace
      X509Certificate2
      /
      X509Certificate
      binary/file constructors with
      X509CertificateLoader
      methods
    • Also
      SYSLIB0055
      (ARM AdvSimd signed overloads) and
      SYSLIB0056
      (Assembly.LoadFrom with hash algorithm) — see
      references/core-libraries-dotnet8to9.md
  4. C# 13
    InlineArray
    on record structs
    [InlineArray]
    attribute on
    record struct
    types is now disallowed (CS9259). Change to a regular
    struct
    . See
    references/csharp-compiler-dotnet8to9.md
    .
  5. C# 13 iterator safe context — Iterators now introduce a safe context in C# 13. Local functions inside iterators that used unsafe code inherited from an outer
    unsafe
    class will now error. Add
    unsafe
    modifier to the local function. See
    references/csharp-compiler-dotnet8to9.md
    .
  6. C# 13 collection expression overload resolution — Empty collection expressions (
    []
    ) no longer use span vs non-span to tiebreak overloads. Exact element type is now preferred. See
    references/csharp-compiler-dotnet8to9.md
    .
  7. String.Trim(params ReadOnlySpan<char>)
    removed
    — Code compiled against .NET 9 previews that passes
    ReadOnlySpan<char>
    to
    Trim
    /
    TrimStart
    /
    TrimEnd
    must rebuild; the overload was removed in GA. See
    references/core-libraries-dotnet8to9.md
    .
  8. BinaryFormatter
    always throws
    — If the project uses
    BinaryFormatter
    , stop and inform the user — this is a major decision. See
    references/serialization-networking-dotnet8to9.md
    .
  9. HttpListenerRequest.UserAgent
    is nullable
    — The property is now
    string?
    . Add null checks. See
    references/serialization-networking-dotnet8to9.md
    .
  10. Windows Forms nullability annotation changes — Some WinForms API parameters changed from nullable to non-nullable. Update call sites. See
    references/winforms-wpf-dotnet8to9.md
    .
  11. Windows Forms security analyzers (WFO1000) — New analyzers produce errors for properties without explicit serialization configuration. See
    references/winforms-wpf-dotnet8to9.md
    .
Build again after each batch of fixes. Repeat until the build is clean.
系统地处理编译错误和新警告。根据项目类型加载相应的参考文档:
如果项目使用…加载参考文档
任意 .NET 9 项目
references/csharp-compiler-dotnet8to9.md
任意 .NET 9 项目
references/core-libraries-dotnet8to9.md
任意 .NET 9 项目
references/sdk-msbuild-dotnet8to9.md
ASP.NET Core
references/aspnet-core-dotnet8to9.md
Entity Framework Core
references/efcore-dotnet8to9.md
加密 API
references/cryptography-dotnet8to9.md
System.Text.Json、HttpClient、网络
references/serialization-networking-dotnet8to9.md
Windows Forms 或 WPF
references/winforms-wpf-dotnet8to9.md
Docker 容器、原生互操作
references/containers-interop-dotnet8to9.md
运行时配置、部署
references/deployment-runtime-dotnet8to9.md
需检查的常见源代码不兼容变更:
  1. params
    span 重载解析
    ——
    String.Join
    String.Concat
    Path.Combine
    Task.WhenAll
    等方法新增的
    params ReadOnlySpan<T>
    重载现在会被优先绑定。在
    Expression
    lambda 中调用这些方法的代码会失败(CS8640/CS9226)。请参阅
    references/core-libraries-dotnet8to9.md
  2. StringValues
    重载歧义
    ——
    params Span<T>
    特性会导致
    String.Concat
    String.Join
    Path.Combine
    等方法与
    StringValues
    隐式运算符产生歧义。通过显式转换参数来修复。请参阅
    references/core-libraries-dotnet8to9.md
  3. 新的过时警告(SYSLIB0054–SYSLIB0057)
    • SYSLIB0054
      :将
      Thread.VolatileRead
      /
      VolatileWrite
      替换为
      Volatile.Read
      /
      Volatile.Write
    • SYSLIB0057
      :将
      X509Certificate2
      /
      X509Certificate
      二进制/文件构造函数替换为
      X509CertificateLoader
      方法
    • 还有
      SYSLIB0055
      (ARM AdvSimd 有符号重载)和
      SYSLIB0056
      (带哈希算法的
      Assembly.LoadFrom
      )——请参阅
      references/core-libraries-dotnet8to9.md
  4. C# 13 记录结构体上的
    InlineArray
    ——现在不允许在
    record struct
    类型上使用
    [InlineArray]
    属性(CS9259)。将其改为常规
    struct
    。请参阅
    references/csharp-compiler-dotnet8to9.md
  5. C# 13 迭代器安全上下文——C# 13 中迭代器现在会引入安全上下文。迭代器内部使用不安全代码的本地函数如果继承自外部
    unsafe
    类,现在会报错。为本地函数添加
    unsafe
    修饰符。请参阅
    references/csharp-compiler-dotnet8to9.md
  6. C# 13 集合表达式重载解析——空集合表达式(
    []
    )不再使用 span 与非 span 来区分重载。现在优先选择精确匹配元素类型。请参阅
    references/csharp-compiler-dotnet8to9.md
  7. String.Trim(params ReadOnlySpan<char>)
    已移除
    ——针对 .NET 9 预览版编译的、向
    Trim
    /
    TrimStart
    /
    TrimEnd
    传递
    ReadOnlySpan<char>
    的代码必须重新编译;该重载在正式版中已被移除。请参阅
    references/core-libraries-dotnet8to9.md
  8. BinaryFormatter
    始终抛出异常
    ——如果项目使用
    BinaryFormatter
    请停止操作并告知用户——这是一个重大决策。请参阅
    references/serialization-networking-dotnet8to9.md
  9. HttpListenerRequest.UserAgent
    可为空
    ——该属性现在为
    string?
    。添加空值检查。请参阅
    references/serialization-networking-dotnet8to9.md
  10. Windows Forms 可空性注解变更——部分 WinForms API 参数从可空改为非可空。更新调用位置。请参阅
    references/winforms-wpf-dotnet8to9.md
  11. Windows Forms 安全分析器(WFO1000)——新的分析器会对未配置显式序列化的属性产生错误。请参阅
    references/winforms-wpf-dotnet8to9.md
每修复一批问题后重新构建。重复此过程直至构建成功。

Step 4: Address behavioral changes

步骤4:处理行为变更

Behavioral changes do not cause build errors but may change runtime behavior. Review each applicable item and determine whether the previous behavior was relied upon.
High-impact behavioral changes (check first):
  1. Floating-point to integer conversions are now saturating — Conversions from
    float
    /
    double
    to integer types now saturate instead of wrapping on x86/x64. See
    references/deployment-runtime-dotnet8to9.md
    .
  2. EF Core: Pending model changes exception
    Migrate()
    /
    MigrateAsync()
    now throws if the model has pending changes. Search for
    DateTime.Now
    ,
    DateTime.UtcNow
    , or
    Guid.NewGuid()
    in any
    HasData
    call — these must be replaced with fixed constants
    (e.g.,
    new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc)
    ). See
    references/efcore-dotnet8to9.md
    .
  3. EF Core: Explicit transaction exception
    Migrate()
    inside a user transaction now throws. See
    references/efcore-dotnet8to9.md
    .
  4. HttpClientFactory uses
    SocketsHttpHandler
    by default
    — Code that casts the primary handler to
    HttpClientHandler
    will get
    InvalidCastException
    . See
    references/serialization-networking-dotnet8to9.md
    .
  5. HttpClientFactory header redaction by default — All header values in
    Trace
    -level logs are now redacted. See
    references/serialization-networking-dotnet8to9.md
    .
  6. Environment variables take precedence over runtimeconfig.json — Runtime configuration settings from environment variables now override
    runtimeconfig.json
    . See
    references/deployment-runtime-dotnet8to9.md
    .
  7. ASP.NET Core
    ValidateOnBuild
    /
    ValidateScopes
    in development
    HostBuilder
    now enables DI validation in development by default. See
    references/aspnet-core-dotnet8to9.md
    .
Other behavioral changes to review (may cause runtime exceptions ⚠️ or subtle behavioral differences):
  • ⚠️
    FromKeyedServicesAttribute
    no longer injects non-keyed service fallback — throws
    InvalidOperationException
  • ⚠️ Container images no longer install zlib — apps depending on system zlib will fail
  • ⚠️ Intel CET is now enabled by default — non-CET-compatible native libraries may cause process termination
  • BigInteger
    now has a maximum length of
    (2^31) - 1
    bits
  • JsonDocument
    deserialization of JSON
    null
    now returns non-null
    JsonDocument
    with
    JsonValueKind.Null
    instead of C#
    null
  • System.Text.Json
    metadata reader now unescapes metadata property names
  • ZipArchiveEntry
    names/comments now respect the UTF-8 flag
  • IncrementingPollingCounter
    initial callback is now asynchronous
  • InMemoryDirectoryInfo
    prepends rootDir to files
  • RuntimeHelpers.GetSubArray
    returns a different type
  • PictureBox
    raises
    HttpRequestException
    instead of
    WebException
  • StatusStrip
    uses a different default renderer
  • IMsoComponent
    support is opt-in
  • SafeEvpPKeyHandle.DuplicateHandle
    up-refs the handle
  • HttpClient
    metrics report
    server.port
    unconditionally
  • URI query strings redacted in HttpClient EventSource events and IHttpClientFactory logs
  • dotnet watch
    is incompatible with Hot Reload for old frameworks
  • WPF
    GetXmlNamespaceMaps
    returns
    Hashtable
    instead of
    String
行为变更不会导致构建错误,但可能会改变运行时行为。审查每个适用项并确定是否依赖于之前的行为。
高影响行为变更(优先检查):
  1. 浮点型转整型转换现在采用饱和模式——在 x86/x64 平台上,
    float
    /
    double
    转整型的转换现在会饱和而不是环绕。请参阅
    references/deployment-runtime-dotnet8to9.md
  2. EF Core:待处理模型变更异常——
    Migrate()
    /
    MigrateAsync()
    现在会在模型有待处理变更时抛出异常。搜索所有
    HasData
    调用中的
    DateTime.Now
    DateTime.UtcNow
    Guid.NewGuid()
    ——这些必须替换为固定常量
    (例如:
    new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc)
    )。请参阅
    references/efcore-dotnet8to9.md
  3. EF Core:显式事务异常——在用户事务中调用
    Migrate()
    现在会抛出异常。请参阅
    references/efcore-dotnet8to9.md
  4. HttpClientFactory 默认使用
    SocketsHttpHandler
    ——将主处理程序强制转换为
    HttpClientHandler
    的代码会抛出
    InvalidCastException
    。请参阅
    references/serialization-networking-dotnet8to9.md
  5. HttpClientFactory 默认启用标头脱敏——
    Trace
    级日志中的所有标头值现在都会被脱敏。请参阅
    references/serialization-networking-dotnet8to9.md
  6. 环境变量优先级高于 runtimeconfig.json——环境变量中的运行时配置设置现在会覆盖
    runtimeconfig.json
    。请参阅
    references/deployment-runtime-dotnet8to9.md
  7. ASP.NET Core 开发环境中的
    ValidateOnBuild
    /
    ValidateScopes
    ——
    HostBuilder
    现在在开发环境中默认启用依赖注入验证。请参阅
    references/aspnet-core-dotnet8to9.md
其他需审查的行为变更(可能导致运行时异常 ⚠️ 或细微的行为差异):
  • ⚠️
    FromKeyedServicesAttribute
    不再注入非键控服务回退——会抛出
    InvalidOperationException
  • ⚠️ 容器镜像不再安装 zlib——依赖系统 zlib 的应用会失败
  • ⚠️ Intel CET 现在默认启用——不兼容 CET 的原生库可能会导致进程终止
  • BigInteger
    现在的最大长度为
    (2^31) - 1
  • JsonDocument
    反序列化 JSON
    null
    现在会返回非空的
    JsonDocument
    JsonValueKind.Null
    )而非 C#
    null
  • System.Text.Json
    元数据读取器现在会对元数据属性名称进行转义还原
  • ZipArchiveEntry
    名称/注释现在会遵循 UTF-8 标志
  • IncrementingPollingCounter
    初始回调现在为异步
  • InMemoryDirectoryInfo
    会在文件前添加 rootDir
  • RuntimeHelpers.GetSubArray
    返回不同的类型
  • PictureBox
    现在抛出
    HttpRequestException
    而非
    WebException
  • StatusStrip
    使用不同的默认呈现器
  • IMsoComponent
    支持为可选启用
  • SafeEvpPKeyHandle.DuplicateHandle
    会向上引用句柄
  • HttpClient
    指标会无条件报告
    server.port
  • HttpClient EventSource 事件和 IHttpClientFactory 日志中的 URI 查询字符串会被脱敏
  • dotnet watch
    与旧框架的热重载不兼容
  • WPF
    GetXmlNamespaceMaps
    返回
    Hashtable
    而非
    String

Step 5: Update infrastructure

步骤5:更新基础设施

  1. Dockerfiles: Update base images. Note that .NET 9 container images no longer install zlib. If your app depends on zlib, add
    RUN apt-get update && apt-get install -y zlib1g
    to your Dockerfile.
    dockerfile
    # Before
    FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
    FROM mcr.microsoft.com/dotnet/aspnet:8.0
    # After
    FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
    FROM mcr.microsoft.com/dotnet/aspnet:9.0
  2. CI/CD pipelines: Update SDK version references. If using
    global.json
    , update:
    json
    {
      "sdk": {
        "version": "9.0.100",
        "rollForward": "latestFeature"
      }
    }
    Review the
    rollForward
    policy — if set to
    "disable"
    or
    "latestPatch"
    , the SDK may not resolve correctly after upgrading.
    "latestFeature"
    (recommended) allows the SDK to roll forward to the latest 9.0.x feature band.
  3. Visual Studio version: .NET 9 SDK requires VS 17.12+ to target
    net9.0
    . VS 17.11 can only target
    net8.0
    and earlier.
  4. Terminal Logger:
    dotnet build
    now uses Terminal Logger by default in interactive terminals. CI scripts that parse MSBuild console output may need
    --tl:off
    or
    MSBUILDTERMINALLOGGER=off
    .
  5. dotnet workload
    output
    : Output format has changed. Update any scripts that parse workload command output.
  6. .NET Monitor images: Tags simplified to version-only (affects container orchestration referencing specific tags).
  1. Dockerfile:更新基础镜像。注意 .NET 9 容器镜像不再安装 zlib。如果应用依赖 zlib,请在 Dockerfile 中添加
    RUN apt-get update && apt-get install -y zlib1g
    dockerfile
    # 之前
    FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
    FROM mcr.microsoft.com/dotnet/aspnet:8.0
    # 之后
    FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
    FROM mcr.microsoft.com/dotnet/aspnet:9.0
  2. CI/CD 流水线:更新 SDK 版本引用。如果使用
    global.json
    ,请更新:
    json
    {
      "sdk": {
        "version": "9.0.100",
        "rollForward": "latestFeature"
      }
    }
    审查
    rollForward
    策略——如果设置为
    "disable"
    "latestPatch"
    ,升级后 SDK 可能无法正确解析。推荐使用
    "latestFeature"
    ,它允许 SDK 向前兼容至最新的 9.0.x 功能版本。
  3. Visual Studio 版本:.NET 9 SDK 需要 VS 17.12+ 才能以
    net9.0
    为目标框架。VS 17.11 仅支持以
    net8.0
    及更早版本为目标框架。
  4. 终端日志记录器
    dotnet build
    现在在交互式终端中默认使用终端日志记录器。解析 MSBuild 控制台输出的 CI 脚本可能需要添加
    --tl:off
    或设置
    MSBUILDTERMINALLOGGER=off
  5. dotnet workload
    输出
    :输出格式已变更。更新所有解析 workload 命令输出的脚本。
  6. .NET Monitor 镜像:标签简化为仅包含版本(会影响引用特定标签的容器编排)。

Step 6: Verify

步骤6:验证

  1. Run a full clean build:
    dotnet build --no-incremental
  2. Run all tests:
    dotnet test
  3. If the application is containerized, build and test the container image
  4. Smoke-test the application, paying special attention to:
    • BinaryFormatter usage (will throw at runtime)
    • Floating-point to integer conversion behavior
    • EF Core migration application
    • HttpClientFactory handler casting and logging
    • DI validation in development environment
    • Runtime configuration settings (environment variable precedence)
  5. Review the diff and ensure no unintended behavioral changes were introduced
  1. 执行完整的清理构建:
    dotnet build --no-incremental
  2. 运行所有测试:
    dotnet test
  3. 如果应用是容器化的,请构建并测试容器镜像
  4. 对应用进行冒烟测试,特别关注以下内容:
    • BinaryFormatter 使用情况(运行时会抛出异常)
    • 浮点型转整型的转换行为
    • EF Core 迁移应用
    • HttpClientFactory 处理程序强制转换和日志
    • 开发环境中的依赖注入验证
    • 运行时配置设置(环境变量优先级)
  5. 审查差异,确保未引入非预期的行为变更

Reference Documents

参考文档

The
references/
folder contains detailed breaking change information organized by technology area. Load only the references relevant to the project being migrated:
Reference fileWhen to load
references/csharp-compiler-dotnet8to9.md
Always (C# 13 compiler breaking changes — InlineArray on records, iterator safe context, collection expression overloads)
references/core-libraries-dotnet8to9.md
Always (applies to all .NET 9 projects)
references/sdk-msbuild-dotnet8to9.md
Always (SDK and build tooling changes)
references/aspnet-core-dotnet8to9.md
Project uses ASP.NET Core
references/efcore-dotnet8to9.md
Project uses Entity Framework Core
references/cryptography-dotnet8to9.md
Project uses System.Security.Cryptography or X.509 certificates
references/serialization-networking-dotnet8to9.md
Project uses BinaryFormatter, System.Text.Json, HttpClient, or networking APIs
references/winforms-wpf-dotnet8to9.md
Project uses Windows Forms or WPF
references/containers-interop-dotnet8to9.md
Project uses Docker containers or native interop (P/Invoke)
references/deployment-runtime-dotnet8to9.md
Project uses runtime configuration, deployment, or has floating-point to integer conversions
references/
文件夹包含按技术领域分类的详细重大变更信息。仅加载与当前迁移项目相关的参考文档:
参考文件加载时机
references/csharp-compiler-dotnet8to9.md
始终加载(C# 13 编译器重大变更——记录结构体上的 InlineArray、迭代器安全上下文、集合表达式重载)
references/core-libraries-dotnet8to9.md
始终加载(适用于所有 .NET 9 项目)
references/sdk-msbuild-dotnet8to9.md
始终加载(SDK 和构建工具变更)
references/aspnet-core-dotnet8to9.md
项目使用 ASP.NET Core 时
references/efcore-dotnet8to9.md
项目使用 Entity Framework Core 时
references/cryptography-dotnet8to9.md
项目使用 System.Security.Cryptography 或 X.509 证书时
references/serialization-networking-dotnet8to9.md
项目使用 BinaryFormatter、System.Text.Json、HttpClient 或网络 API 时
references/winforms-wpf-dotnet8to9.md
项目使用 Windows Forms 或 WPF 时
references/containers-interop-dotnet8to9.md
项目使用 Docker 容器或原生互操作(P/Invoke)时
references/deployment-runtime-dotnet8to9.md
项目使用运行时配置、部署或存在浮点型转整型转换时