RHEL 10 中使用 .NET 9.0


.NET 9.0

在 RHEL 10 上安装并运行 .NET 9.0

Red Hat Customer Content Services

摘要

本指南论述了如何在 RHEL 10 上安装和运行 .NET 9.0

对红帽文档提供反馈

我们感谢您对我们文档的反馈。让我们了解如何改进它。

通过 Jira 提交反馈(需要帐户)

  1. 登录到 Jira 网站。
  2. 在顶部导航栏中点 Create
  3. Summary 字段中输入描述性标题。
  4. Description 字段中输入您对改进的建议。包括文档相关部分的链接。
  5. 点对话框底部的 Create

第 1 章 .NET 9.0 简介

.NET 是一个通用开发平台,它带有自动内存管理和现代编程语言。使用 .NET,您可以有效地构建高质量的应用程序。通常,.NET 通过认证的容器在 Red Hat Enterprise Linux (RHEL)和 OpenShift Container Platform 上提供。

.NET 提供以下功能:

  • 能够遵循基于微服务的方法,其中某些组件使用 .NET 构建,其他组件则使用 Java 构建,但所有组件都可以在 RHEL 和 OpenShift Container Platform 上的通用支持的平台中运行。
  • 在 Microsoft Windows 上更轻松地开发新的 .NET 工作负载的能力。您可以在 RHEL 或 Windows Server 上部署并运行应用程序。
  • 一个异构的数据中心,底层基础结构可以在不需要依赖 Windows 服务器的情况下运行 .NET 应用程序。

第 2 章 安装 .NET 9.0

.NET 9.0 包括在 RHEL 10 的 AppStream 存储库中。AppStream 软件仓库在 RHEL 10 系统中默认启用。

您可以使用最新的 .NET Software Development Kit (SDK)安装 .NET 9.0 运行时。当较新的 SDK 可供 .NET 9.0 使用时,您可以使用 dnf 安装它。

先决条件

流程

  • 安装 .NET 9.0 及其所有依赖项:

    $ sudo dnf install dotnet-sdk-9.0 -y
    Copy to Clipboard

验证

  • 验证安装:

    $ dotnet --info
    Copy to Clipboard

    输出返回有关 .NET 安装和环境的相关信息。

第 3 章 使用 .NET 9.0 创建应用程序

了解如何创建 C""Hello World"应用程序。

流程

  1. 在名为 my-app 的目录中创建一个新的 Console 应用程序:

    $ dotnet new console --output <my-app>
    Copy to Clipboard
  2. 运行项目:

    $ dotnet run --project <my-app>
    Copy to Clipboard

    输出返回:

    Hello World!
    Copy to Clipboard

第 4 章 使用 .NET 9.0 发布应用程序

.NET 9.0 应用程序可以发布,以使用共享的系统范围 .NET 版本,或包含 .NET。

发布 .NET 9.0 应用程序有以下方法:

  • 自助包含部署(SCD)- 应用程序包括 .NET。此方法使用 Microsoft 构建的运行时。
  • 框架依赖的部署(FDD)- 应用程序使用共享的系统范围版本 .NET。
注意

当为 RHEL 发布应用程序时,红帽建议使用 FDD,因为它确保应用程序使用最新的 .NET 版本(由红帽构建)来使用一组原生依赖项。

先决条件

4.1. 发布 .NET 9.0 应用程序

以下流程概述了如何发布与框架相关的应用程序。

流程

  1. 发布与框架相关的应用程序:

    $ dotnet publish <my-app> -f net9.0
    Copy to Clipboard
    注意

    <my-app > 替换为您要发布的应用程序的名称。

  2. 可选:如果应用程序仅适用于 RHEL,请修剪其他平台所需的依赖项:

    $ dotnet publish <my-app> -f net9.0 -r rhel.10-architecture --self-contained false
    Copy to Clipboard
    • 根据您使用的平台替换 构架

      • 对于 Intel: x64
      • 对于 IBM Z 和 LinuxONE: s390x
      • 对于 64 位 Arm: arm64
      • 对于 IBM Power: ppc64le

第 5 章 在容器中运行 .NET 9.0 应用程序

使用 ubi8/dotnet-90-runtime 镜像在 Linux 容器中运行 .NET 应用程序。

以下示例使用 Podman。

流程

  1. 在名为 mvc_runtime_example 的目录中创建一个新的 MVC 项目:

    $ dotnet new mvc --output mvc_runtime_example
    Copy to Clipboard
  2. 发布项目:

    $ dotnet publish mvc_runtime_example -f net9.0 /p:PublishProfile=DefaultContainer /p:ContainerBaseImage=registry.access.redhat.com/ubi8/dotnet-90-runtime:latest
    Copy to Clipboard
  3. 运行您的镜像:

    $ podman run -rm -p8080:8080 mvc_runtime_example
    Copy to Clipboard
  4. 查看容器中运行的应用程序:

    $ xdg-open http://127.0.0.1:8080
    Copy to Clipboard

第 6 章 从以前的 .NET 版本迁移

6.1. 从 .NET 版本迁移

Microsoft 提供了从以前的 .NET Core 版本迁移的说明。

如果您使用不再支持的 .NET 版本,或希望迁移到较新的 .NET 版本以扩展功能,请参阅以下文章:

注意

如果从 .NET Core 1.x 迁移到 2.0,请参阅从 ASP.NET Core 1.x 迁移到 2.0 中的前几个相关部分。这些部分提供了 .NET Core 1.x 到 2.0 迁移路径的指导。

6.2. 从 .NET Framework 移植

从 .NET Framework 迁移时,请参考以下 Microsoft 文章:

.NET Framework 中存在的一些技术和 API 不在 .NET Core 和 .NET 中。如果您的应用程序或库需要这些 API,请考虑查找替代方案或继续使用 .NET Framework..NET Core 和 .NET 不支持以下技术和 API:

  • 桌面应用程序,如 Windows Forms 和 Windows 演示基础(WPF)
  • 支持 Windows 通信基础(WCF)服务器(WCF 客户端)
  • .NET 远程

另外,一些 .NET API 只能在 Microsoft Windows 环境中使用。以下列表显示了这些 Windows 特定 API 的示例:

  • Microsoft.Win32.Registry
  • System.AppDomains
  • System.Security.Principal.Windows
重要

Microsoft.Windows.Compatibility NuGet 软件包中可能提供了默认版本的 .NET 不支持的几个 API。使用此 NuGet 软件包时要小心。提供的一些 API (如 Microsoft.Win32.Registry)仅适用于 Windows,使您的应用程序与 Red Hat Enterprise Linux 不兼容。

法律通告

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat