.NET Core RID 目录.NET Core RID Catalog

RID 是运行时标识符 的缩写。RID is short for Runtime IDentifier. RID 值用于标识应用程序运行所在的目标平台。RID values are used to identify target platforms where the application runs. .NET 包使用它们来表示 NuGet 包中特定于平台的资产。They're used by .NET packages to represent platform-specific assets in NuGet packages. 以下值是 RID 的示例:linux-x64ubuntu.14.04-x64win7-x64osx.10.12-x64The following values are examples of RIDs: linux-x64, ubuntu.14.04-x64, win7-x64, or osx.10.12-x64. 对于具有本机依赖项的包,RID 将指定在其中可以还原包的平台。For the packages with native dependencies, the RID designates on which platforms the package can be restored.

可以在项目文件的 <RuntimeIdentifier> 元素中设置一个 RID。A single RID can be set in the <RuntimeIdentifier> element of your project file. 可以将多个 RID 定义为项目文件的 <RuntimeIdentifiers> 元素中的列表(以分号分隔)。Multiple RIDs can be defined as a semicolon-delimited list in the project file's <RuntimeIdentifiers> element. 也可使用以下 .NET Core CLI 命令 通过 --runtime 选项使用它们:They're also used via the --runtime option with the following .NET Core CLI commands:

表示具体操作系统的 RID 通常遵循以下模式:[os].[version]-[architecture]-[additional qualifiers],其中:RIDs that represent concrete operating systems usually follow this pattern: [os].[version]-[architecture]-[additional qualifiers] where:

  • [os] 是操作系统/平台系统名字对象。[os] is the operating/platform system moniker. 例如 ubuntuFor example, ubuntu.

  • [version] 是操作系统版本,使用的格式是以点 (.) 分隔的版本号。[version] is the operating system version in the form of a dot-separated (.) version number. 例如 15.10For example, 15.10.

    • 版本不应 为营销版本,因为它们通常代表该操作系统的多个离散版本,且具有不同的平台 API 外围应用。The version shouldn't be marketing versions, as they often represent multiple discrete versions of the operating system with varying platform API surface area.
  • [architecture] 是处理器体系结构。[architecture] is the processor architecture. 例如:x86x64armarm64For example: x86, x64, arm, or arm64.

  • [additional qualifiers] 进一步区分了不同的平台。[additional qualifiers] further differentiate different platforms. 例如:aotFor example: aot.

RID 图表RID graph

RID 图表或运行时回退图表是互相兼容的 RID 列表。The RID graph or runtime fallback graph is a list of RIDs that are compatible with each other. Microsoft.NETCore.Platforms 包中定义了 RID。The RIDs are defined in the Microsoft.NETCore.Platforms package. 可以在 CoreFX 存储库的 runtime.json 文件中查看支持的 RID 列表和 RID 图表。You can see the list of supported RIDs and the RID graph in the runtime.json file, which is located at the CoreFX repo. 在此文件中,可以看到除基 RID 以外的所有 RID 均包含 "#import" 语句。In this file, you can see that all RIDs, except for the base one, contain an "#import" statement. 这些语句指示的是兼容的 RID。These statements indicate compatible RIDs.

NuGet 还原包时,它将尝试找到指定运行时的完全匹配项。When NuGet restores packages, it tries to find an exact match for the specified runtime. 如果未找到完全匹配项,NuGet 将返回此图表,直至它根据 RID 图表找到最相近的兼容系统。If an exact match is not found, NuGet walks back the graph until it finds the closest compatible system according to the RID graph.

以下示例是 osx.10.12-x64 RID 的实际条目:The following example is the actual entry for the osx.10.12-x64 RID:

"osx.10.12-x64": {
    "#import": [ "osx.10.12", "osx.10.11-x64" ]
}

上述 RID 指定 osx.10.12-x64 导入 osx.10.11-x64The above RID specifies that osx.10.12-x64 imports osx.10.11-x64. 因此,当 NuGet 还原包时,它将尝试找到包中的 osx.10.12-x64 的完全匹配项。So, when NuGet restores packages, it tries to find an exact match for osx.10.12-x64 in the package. 例如,如果 NuGet 无法找到特定的运行时,可以还原指定 osx.10.11-x64 运行时的包。If NuGet cannot find the specific runtime, it can restore packages that specify osx.10.11-x64 runtimes, for example.

以下示例演示了 runtime.json 文件中定义的另一个略大的 RID 图表:The following example shows a slightly bigger RID graph also defined in the runtime.json file:

    win7-x64    win7-x86
       |   \   /    |
       |   win7     |
       |     |      |
    win-x64  |  win-x86
          \  |  /
            win
             |
            any

所有 RID 最终都会映射回根 any RID。All RIDs eventually map back to the root any RID.

使用 RID 时,必须牢记以下几个注意事项:There are some considerations about RIDs that you have to keep in mind when working with them:

  • RID 是不透明字符串 ,应将其视为黑盒。RIDs are opaque strings and should be treated as black boxes.
  • 请勿以编程方式生成 RID。Don't build RIDs programmatically.
  • 使用已为平台定义的 RID。Use RIDs that are already defined for the platform.
  • RID 必须具有特定性,因此请勿通过实际的 RID 值假定任何情况。The RIDs need to be specific, so don't assume anything from the actual RID value.

使用 RIDUsing RIDs

若要使用 RID,必须知道有哪些 RID。To be able to use RIDs, you have to know which RIDs exist. 新值将定期添加到该平台。New values are added regularly to the platform. 若要获取最新的完整版,请参阅 CoreFX 存储库上的 runtime.json 文件。For the latest and complete version, see the runtime.json file on CoreFX repo.

.NET Core 2.0 SDK 引入了可移植 RID 的概念。.NET Core 2.0 SDK introduces the concept of portable RIDs. 它们是添加到 RID 图表的新值,并且未与特定版本或 OS 发行版本关联,是使用 .NET Core 2.0 及更高版本的首选值。They are new values added to the RID graph that aren't tied to a specific version or OS distribution and are the preferred choice when using .NET Core 2.0 and higher. 它们在处理多个 Linux 发行版时特别有用,因为大多数发行版 RID 都映射到可移植的 RID。They're particularly useful when dealing with multiple Linux distros since most distribution RIDs are mapped to the portable RIDs.

以下列表显示了一小部分用于每个 OS 的最常见 RID。The following list shows a small subset of the most common RIDs used for each OS.

Windows RIDWindows RIDs

仅列出了公共值。Only common values are listed. 若要获取最新的完整版,请参阅 CoreFX 存储库上的 runtime.json 文件。For the latest and complete version, see the runtime.json file on CoreFX repo.

  • 可移植(.NET Core 2.0 或更高版本)Portable (.NET Core 2.0 or later versions)
    • win-x64
    • win-x86
    • win-arm
    • win-arm64
  • Windows 7 / Windows Server 2008 R2Windows 7 / Windows Server 2008 R2
    • win7-x64
    • win7-x86
  • Windows 8.1 / Windows Server 2012 R2Windows 8.1 / Windows Server 2012 R2
    • win81-x64
    • win81-x86
    • win81-arm
  • Windows 10 / Windows Server 2016Windows 10 / Windows Server 2016
    • win10-x64
    • win10-x86
    • win10-arm
    • win10-arm64

有关详细信息,请参阅 Windows 上 .NET Core 的先决条件See Prerequisites for .NET Core on Windows for more information.

Linux RIDLinux RIDs

仅列出了公共值。Only common values are listed. 若要获取最新的完整版,请参阅 CoreFX 存储库上的 runtime.json 文件。For the latest and complete version, see the runtime.json file on CoreFX repo. 运行以下未列出的发行版的设备可能适用于其中一个可移植 RID。Devices running a distribution not listed below may work with one of the Portable RIDs. 例如,可以将运行未列出的 Linux 发行版的 Raspberry Pi 设备定向为使用 linux-armFor example, Raspberry Pi devices running a Linux distribution not listed can be targeted with linux-arm.

  • 可移植(.NET Core 2.0 或更高版本)Portable (.NET Core 2.0 or later versions)
    • linux-x64(大多数桌面发行版,如 CentOS、Debian、Fedora、Ubuntu 及派生版本)linux-x64 (Most desktop distributions like CentOS, Debian, Fedora, Ubuntu and derivatives)
    • linux-musl-x64(使用 musl 的轻量级发行版,如 Alpine Linux)linux-musl-x64 (Lightweight distributions using musl like Alpine Linux)
    • linux-arm(在 ARM 上运行的 Linux 分发版,如 Raspberry Pi)linux-arm (Linux distributions running on ARM like Raspberry Pi)
  • Red Hat Enterprise LinuxRed Hat Enterprise Linux
    • rhel-x64(被 linux-x64 取代,适用于 RHEL 6 以上版本)rhel-x64 (Superseded by linux-x64 for RHEL above version 6)
    • rhel.6-x64(.NET Core 2.0 或更高版本)rhel.6-x64 (.NET Core 2.0 or later versions)
  • Tizen(.NET Core 2.0 或更高版本)Tizen (.NET Core 2.0 or later versions)
    • tizen
    • tizen.4.0.0
    • tizen.5.0.0

有关详细信息,请参阅 Linux 上 .NET Core 的先决条件See Prerequisites for .NET Core on Linux for more information.

macOS RIDmacOS RIDs

macOS RID 使用较早的“OSX”品牌。macOS RIDs use the older "OSX" branding. 仅列出了公共值。Only common values are listed. 若要获取最新的完整版,请参阅 CoreFX 存储库上的 runtime.json 文件。For the latest and complete version, see the runtime.json file on CoreFX repo.

  • 可移植(.NET Core 2.0 或更高版本)Portable (.NET Core 2.0 or later versions)
    • osx-x64(最低 OS 版本为 macOS 10.12 Sierra)osx-x64 (Minimum OS version is macOS 10.12 Sierra)
  • macOS 10.10 YosemitemacOS 10.10 Yosemite
    • osx.10.10-x64
  • macOS 10.11 El CapitanmacOS 10.11 El Capitan
    • osx.10.11-x64
  • macOS 10.12 Sierra(.NET Core 1.1 或更高版本)macOS 10.12 Sierra (.NET Core 1.1 or later versions)
    • osx.10.12-x64
  • macOS 10.13 High Sierra(.NET Core 1.1 或更高版本)macOS 10.13 High Sierra (.NET Core 1.1 or later versions)
    • osx.10.13-x64
  • macOS 10.14 Mojave(.NET Core 1.1 或更高版本)macOS 10.14 Mojave (.NET Core 1.1 or later versions)
    • osx.10.14-x64

有关详细信息,请参阅 macOS 上 .NET Core 的先决条件See Prerequisites for .NET Core on macOS for more information.

请参阅See also