-
Notifications
You must be signed in to change notification settings - Fork 5k
[.NET 9] RuntimeInformation.RuntimeIdentifier
includes unexpected OS details on Linux repo installs
#114156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This issue with RuntimeInformation.RuntimeIdentifier returning OS-specific details on Linux when installed from native repositories can be problematic when you need consistent RIDs. Here's a possible solution that normalizes the RID to the expected format:
This solution:
You can use this normalized RID for your tool downloads instead of directly using For production use, you might want to add more comprehensive detection for other Linux distributions or edge cases, but this covers the main scenarios you described in the issue. Thank You, Prashant Yadav |
Thank you, this is a temporary workaround, I do believe the repo based installers should report the correct information, and workarounds should not be required. I'd like to hear from dotnet if this is in fact a repo installer issue, how they interact with maintainers to get it fixed, and maybe add tests to assure correct RID behavior? |
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov |
This is expected. The distro package managers install distro-specific .NET runtime. The distro-specific .NET runtime has RuntimeIdentifier specific to that distro. What are you trying to do? If you just need to check whether you are running on Linux, there is cc @dotnet/distro-maintainers |
I am trying to get the RID so that I can download the correct single file test tool. The method of using I expect some form of method that returns the RID in a deterministic way, that matches the documentation, regardless of how the runtime was installed. |
@elinor-fung Looks like the documentation isn't quite right. It says that the RID on ubuntu will be linux-x64, but that's dependent on whether they're using a portable or non-portable build, right? |
I guess more problematic is the behavior of published apps, which differ from $ dotnet run
ubuntu.25.04-arm64
# dotnet publish -p:PublishSingleFile=true -o publish-singlefile
$ publish-singlefile/app1
linux-arm64
# dotnet publish -p:PublishAot=true -o publish-aot
$ publish-aot/app1
linux-arm64 At minimum, we should make it consistently return the same RID, either portable or non-portable. This is informational API for telemetry purposes etc. For other use-cases, OperatingSystem.IsXx APIs are preferred as @jkotas has pointed out. However, that does not cover cases like |
Thank you for continuing to investigate. I do want to call out that the .NET diagnostic tooling expects normalized RID's, so I'd still prefer some solution where |
It should probably call that out explicitly. The example is technically correct (version of Ubuntu from when they didn't produce their own packages), but confusing. Tried to clarify in: dotnet/dotnet-api-docs#11203 |
I think this is actually a different case: The SDK specifically uses a portable RID as the default RID when you publish, even if you're on a non-portable SD (see the behavior of This behavior is a reasonable default IMO because otherwise the default publish experience would mean that a project built on a SourceBuild-based SDK (like RHEL) would publish non-portable, whereas building on a Microsoft-build would publish portable. |
Yes I saw the behavior, rather wrote it myself dotnet/sdk@347f78f and it was equally messy back then. Do we want |
I don't think we should be changing the value of Perhaps an additional property, like If you are doing something on the SDK side, there is the The broader use-case is to find a best match among a set of target rids. e.g. I have installers for |
In addition to how user has installed the SDK (from MSFT or the distro), these are some differences: $ apt install -y dotnet-sdk-9.0
$ dotnet new console -n app1 && cd app1
$ cat >Program.cs<<EOF
using System.Runtime.InteropServices;
Console.WriteLine(RuntimeInformation.RuntimeIdentifier);
EOF
$ dotnet run
ubuntu.25.04-arm64
$ dotnet publish --self-contained -o out && out/app1
linux-arm64
$ dotnet publish --self-contained -o sc --ucr && out/app1
ubuntu.25.04-arm64
$ dotnet publish --self-contained -r ubuntu.25.04-arm64 -p:UseRidGraph=true -o out && out/app1
ubuntu.25.04-arm64
$ dotnet publish --self-contained -r ubuntu.22.04-arm64 -p:UseRidGraph=true -o out && out/app1
linux-arm64
$ dotnet publish --self-contained -r fedora.39-arm64 -p:UseRidGraph=true -o out && out/app1
linux-arm64 By reading the remarks section in docs as an API consumer, these output should be explainable without needing to learn the internal infrastructure details of dotnet org. |
In all cases it should be returning the rid the native assets are compatible with (that is: the vmr build
|
Description
Per docs it is expected that
RuntimeInformation.RuntimeIdentifier
returns OS agnostic RID's.In my testing the RID's returned on some Linux installs includes the OS name, this is not expected, and breaks usage of the reported RID. (I use the RID to download single file dotnet tools)
Note that the issue may be related to how the SDK/runtime was built and installed, as the behavior on Windows (.NET sourced rom Msft, and Debian (.NET sourced from install script) appear to work, while the SDK/runtime installed using the OS native repository does not produce the correct results.
Summary:
Win11 Msft download : Ok
Debian
https://dot.net/v1/dotnet-install.sh
: OkUbuntu dotnet-runtime-9.0 : Fail
Alpine dotnet9-runtime : Fail
Reproduction Steps
Windows 11 x64, .NET 9 SDK installed: (Ok)
dotnet --info
->RID: win-x64
Console.WriteLine(RuntimeInformation.RuntimeIdentifier);
->win-x64
Alpine, docker
alpine:latest
,apk add dotnet9-runtime
(Fail)dotnet --info
->RID: alpine.3.21-x64
(expectedlinux-musl-x64
)Console.WriteLine(RuntimeInformation.RuntimeIdentifier);
->alpine.3.21-x64
(expectedlinux-musl-x64
)Debian, docker
debian:stable-slim
,https://dot.net/v1/dotnet-install.sh
(Ok)dotnet --info
->RID: linux-x64
Console.WriteLine(RuntimeInformation.RuntimeIdentifier);
->linux-x64
Ubuntu, docker
ubuntu:rolling
,dotnet-runtime-9.0
(Fail)dotnet --info
->RID: ubuntu.24.10-x64
(expectedlinux-x64
)Console.WriteLine(RuntimeInformation.RuntimeIdentifier);
->ubuntu.24.10-x64
(expectedlinux-x64
)Expected behavior
RID returned in
dotnet --info
andRuntimeInformation.RuntimeIdentifier
is consistent with documentation.Actual behavior
See reproduction steps, it appears that .NET installed via Linux native repos do not return the correct RID.
Regression?
I last tested this behavior in .NET v7 and it worked then, but that was a long time ago.
Known Workarounds
Always install using Msft helper script, but that is not recommended for production use.
Configuration
.NET 9.0.3
See description for install steps on Docker.
Other information
No response
The text was updated successfully, but these errors were encountered: