RID is short for runtime identifier. RID values are used to identify target platforms where the application runs.
They're used by .NET packages to represent platform-specific assets in NuGet packages. The following values are examples of RIDs: linux-x64, win-x64, or osx-x64.
For the packages with native dependencies, the RID designates on which platforms the package can be restored.
A single RID can be set in the <RuntimeIdentifier> element of your project file. Multiple RIDs can be defined as a semicolon-delimited list in the project file's <RuntimeIdentifiers> element. They're also used via the --runtime option with the following .NET CLI commands:
RIDs that represent concrete operating systems usually follow this pattern: [os].[version]-[architecture]-[additional qualifiers] where:
[os] is the operating/platform system moniker. For example, ubuntu.
[version] is the operating system version in the form of a dot-separated (.) version number. For example, 15.10.
The version shouldn't be a marketing version, as marketing versions often represent multiple discrete versions of the operating system with varying platform API surface area.
[architecture] is the processor architecture. For example: x86, x64, arm, or arm64.
[additional qualifiers] further differentiate different platforms. For example: aot.
RID graph
The RID graph or runtime fallback graph is a list of RIDs that are compatible with each other.
These RIDs are defined in PortableRuntimeIdentifierGraph.json in the dotnet/runtime repository. In this file, you can see that all RIDs, except for the base one, contain an "#import" statement. These statements indicate compatible RIDs.
Before .NET 8, version-specific and distro-specific RIDs were regularly added to the runtime.json file, which is located in the dotnet/runtime repository. This graph is no longer updated and exists as a backwards compatibility option. Developers should use RIDs that are non-version-specific and non-distro-specific.
When NuGet restores packages, it tries to find an exact match for the specified runtime.
If an exact match is not found, NuGet walks back the graph until it finds the closest compatible system according to the RID graph.
The following example is the actual entry for the osx-x64 RID:
JSON
"osx-x64": {
"#import": [ "osx", "unix-x64" ]
}
The above RID specifies that osx-x64 imports unix-x64. So, when NuGet restores packages, it tries to find an exact match for osx-x64 in the package. If NuGet can't find the specific runtime, it can restore packages that specify unix-x64 runtimes, for example.
The following example shows a slightly bigger RID graph also defined in the runtime.json file:
Some apps need to compute RIDs programmatically. If so, the computed RIDs must match the catalog exactly, including in casing. RIDs with different casing would cause problems when the OS is case sensitive, for example, Linux, because the value is often used when constructing things like output paths. For example, consider a custom publishing wizard in Visual Studio that relies on information from the solution configuration manager and project properties. If the solution configuration passes an invalid value, for example, ARM64 instead of arm64, it could result in an invalid RID, such as win-ARM64.
Loading assets for a specific OS version or distribution
.NET no longer attempts to provide first-class support for resolving dependencies that are specific to an OS version or distribution. If your application or package needs to load different assets based on OS version or distribution, it should implement the logic to conditionally load assets.
To get information about the platform, use System.OperatingSystem APIs. On Windows and macOS, Environment.OSVersion will return the operating system version. On Linux, it may be the kernel version—to get the Linux distro name and version information, the recommended approach is to read the /etc/os-release file.
The following list shows a small subset of the most common RIDs used for each OS. For the latest and complete version, see the PortableRuntimeIdentifierGraph.json in the dotnet/runtime repository.
Μπορείτε να βρείτε την πηγή για αυτό το περιεχόμενο στο GitHub, όπου μπορείτε επίσης να δημιουργήσετε και να εξετάσετε ζητήματα και αιτήματα έλξης. Για περισσότερες πληροφορίες, ανατρέξτε στον οδηγό συνεργατών.
.NET σχόλια
.NET είναι ένα έργο ανοιχτού κώδικα. Επιλέξτε μια σύνδεση για να παρέχετε σχόλια:
Συμμετάσχετε στη σειρά meetup για να δημιουργήσετε κλιμακούμενες λύσεις AI που βασίζονται σε πραγματικές περιπτώσεις χρήσης με συναδέλφους προγραμματιστές και ειδικούς.