Skip to content
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

Proposed additions to RuntimeInformation #20400

Closed
leecow opened this issue Mar 2, 2017 · 20 comments
Closed

Proposed additions to RuntimeInformation #20400

leecow opened this issue Mar 2, 2017 · 20 comments
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Runtime
Milestone

Comments

@leecow
Copy link
Member

leecow commented Mar 2, 2017

https://github.com/dotnet/corefx/issues/12737

RuntimeInformation

Rational and Usage

It is often desirable and necessary for applications to determine execution environment and runtime information. Existing information provided by System.Runtime.InteropServices.RuntimeInformation could be enhanced and expanded with additional API to provide robust information.

System.Runtime.InteropServices.RuntimeInformation currently provides surface for some of information though modification to current behavior or addition API may be needed.

Existing API

  • OSPlatform
  • ProcessAchitecture
  • OSArchitecture
  • OSDescription
  • FrameworkDescription
  • IsOSPlatform

Proposed additions

  • OSName - Windows, Mac, Ubuntu, Red Hat Enterprise Linux Server
  • OSVersion - following the previous examples - 10.0.15027, 10.12.3, 16.10, 7.2
  • RuntimeVersions - Runtime version currently used by the application, eg NETCore.App 1.0.4
  • InstalledRuntimeVersions - List of targetable runtime on system

Open Questions

Updates

Appendix

/etc/os-release will have the pertinent information on all systemd-based distros. All distros in our current support set use systemd. Alpine Linux includes /etc/os-release.
Variables can be accessed directly with ( source /etc/os-release && echo "$PRETTY_NAME" )

Fedora:

	NAME=Fedora
	VERSION="24 (Workstation Edition)"
	ID=fedora
	VERSION_ID=24
	PRETTY_NAME="Fedora 24 (Workstation Edition)"
	ANSI_COLOR="0;34"
	CPE_NAME="cpe:/o:fedoraproject:fedora:24"
	HOME_URL="https://fedoraproject.org/"
	BUG_REPORT_URL="https://bugzilla.redhat.com/"
	REDHAT_BUGZILLA_PRODUCT="Fedora"
	REDHAT_BUGZILLA_PRODUCT_VERSION=24
	REDHAT_SUPPORT_PRODUCT="Fedora"
	REDHAT_SUPPORT_PRODUCT_VERSION=24
	PRIVACY_POLICY_URL=https://fedoraproject.org/wiki/Legal:PrivacyPolicy
	VARIANT="Workstation Edition"
	VARIANT_ID=workstation

Alpine:

	NAME="Alpine Linux"
	ID=alpine
	VERSION_ID=3.5.0
	PRETTY_NAME="Alpine Linux v3.5"
	HOME_URL="http://alpinelinux.org"
	BUG_REPORT_URL="http://bugs.alpinelinux.org"

/cc @richlander , @mellinoe , @Petermarcu , @AlexGhiondea , @weshaggard , @danmosemsft

@danmoseley
Copy link
Member

I was literally this morning typing up a proposal to at least add a strongly typed enum for runtime name.

Right now to figure out we are running on desktop, we do string parsing:
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"))

it should be possible to do something like
if (RuntimeInformation.Framework.IsDesktopFramework) or if (RuntimeInformation.FrameworkIs(Frameworks.Desktop))

@weshaggard
Copy link
Member

For the Version APIs how do you propose we determine each of them?

For example for OSVersion not all OS's are pure number based versions, so should this be a string or a new Version type that supports semantic versioning?

For the RuntimeVersion where would we embed this information? Today we don't really have a way to determine what .NET Core you are running on. When running on the shared framework we might be able to figure some of that out but when not I'm not sure where that would come from.

Similar for InstalledRuntimeVersions where would we probe for that information?

Right now to figure out we are running on desktop, we do string parsing:
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"))

@danmosemsft FrameworkDescription is intended for logging information. To determine which framework people built against for runtime checks you should be using AppContext.TargetFramework.

@leecow
Copy link
Member Author

leecow commented Mar 2, 2017

I wouldn't think we would invent anything clever for OSVersion. Return what is readily offered by the system. In the Linux case it happens to look like a number.

Could we rely on the contents of /share/Microsoft.NETCore.App or is that too naive?

@weshaggard
Copy link
Member

I wouldn't think we would invent anything clever for OSVersion. Return what is readily offered by the system. In the Linux case it happens to look like a number.

It can contain more then just numeric versions see https://www.freedesktop.org/software/systemd/man/os-release.html

Could we rely on the contents of /share/Microsoft.NETCore.App or is that too naive?

That might help for shared applications but doesn't help for standalone at all.

@leecow
Copy link
Member Author

leecow commented Mar 2, 2017

It can contain more then just numeric versions

Yes, I understand that. Just suggesting we return whatever is readily available, eg a string.

It can contain more then just numeric versions

That's why the smart folks are here to figure out the options ;-)

@weshaggard
Copy link
Member

Yes, I understand that. Just suggesting we return whatever is readily available, eg a string.

Can I ask you to update the proposal with some scenarios (i.e. coding scenarios) we want folks to be doing with these new APIs? If we plan folks to make runtime decisions based on this version then having it be a string isn't a good way to expose this information because everyone will still have to figure out how to parse it.

That's why the smart folks are here to figure out the options ;-)

There isn't any good way that I'm aware of to do this, that would work across all our .NET Platforms, which is why I'm asking questions.

@MichalStrehovsky
Copy link
Member

For the OSVersion thing, it might not be possible to reliably implement this on Windows (e.g. GetVersionEx will return the version that the program is manifested for and never anything higher - and Windows team is slowly eradicating other undocumented places people use to get Windows version). They really don't want programs to use that to drive decisions.

@mellinoe
Copy link
Contributor

mellinoe commented Mar 3, 2017

And how about the supported in other platforms, like Android, iOS, FreeBSD, etc.? Do we have an idea about what facilities exist there?

@Priya91
Copy link
Contributor

Priya91 commented Mar 3, 2017

If the intention to use os version is to make runtime decisions for the availability of a feature, etc, then we could have an api like CheckFeaturePresent, that could be a wrapper on pinvoke to check the existence of the native library. The point being to understand why os version is required for runtime decisions and find a different way to get that data without having to depend on correctly identifying the os version.

For other purposes like displaying the version, we can just return a string that we get from the OS. How the developer intends to use this string, will be out of scope of the .NET API contract. This API will be similar to os.name, os.version system properties on Java, and runtime.GOOS env variables on Go.

@leecow
Copy link
Member Author

leecow commented Mar 4, 2017

Priya is capturing the primary use category I was envisioning. Namely, this will simply report environment information as presented by the OS and attempting to account for the usage of the data is essentially impossible.

Will add a few scenarios including those which have been raised in other issues to hopefully clarify.

@eerhardt
Copy link
Member

Note we already have OperatingSystem and OperatingSystemVersion in PlatformAbstractions:

https://github.com/dotnet/core-setup/blob/master/src/managed/Microsoft.DotNet.PlatformAbstractions/RuntimeEnvironment.cs#L15-L17

These values are necessary to figure out the RID of the machine.

Can consumers who need these values just use these existing APIs?

@eerhardt
Copy link
Member

@weshaggard @terrajobst - we really should rectify the APIs in PlatformAbstractions with RuntimeInformation.

The APIs in PlatformAbstractions came from needing this functionality in the CLI, but not having the necessary APIs in the BCL. So the CLI team created these APIs and they made their way into dotnet/core-setup. We (the runtime team) own both corefx and core-setup and the APIs exposed by both repos. So we should have a coherent story here.

@tmat
Copy link
Member

tmat commented Apr 17, 2018

Any managed library (such as msbuild task) that loads native library needs to know RID. This need came up recently in libgit2sharp. We should add GetRuntimeId method.

@ghost
Copy link

ghost commented May 10, 2018

Since dotnet/corefx#16629, dotnet/corefx#17452, dotnet/corefx#23197, dotnet/corefx#24522, dotnet/corefx#25530, dotnet/corefx#27417 and dotnet/corefx#28132 are all similar proposals if we think from the perspective of bringing over https://github.com/dotnet/core-setup/tree/fd1dc48fad5bc32258c8c0fc885fbf4b1e32bebd/src/managed/Microsoft.DotNet.PlatformAbstractions to CoreFX that was proposed in https://github.com/dotnet/corefx/issues/28620 by @weshaggard, could the area owner of S.R.I.RuntimeInformation combine these proposals for a more broader API review encompassing various known use-cases?

@Petermarcu
Copy link
Member

@danmosemsft, can we get someone assigned to this? Iike to see a unification proposal that effectively eliminates the need for PlatformAbstractions as a second place to get runtime info.

@ViktorHofer
Copy link
Member

ViktorHofer commented Feb 20, 2019

I closed couple of related issues as duplicates. I agree with "ghost" (https://github.com/dotnet/corefx/issues/16629#issuecomment-388003268) that we should initially focus on bringing over what Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment offers: https://github.com/dotnet/core-setup/blob/master/src/managed/Microsoft.DotNet.PlatformAbstractions/RuntimeEnvironment.cs#L14-L31.

public static partial class RuntimeInformation
{
    private static string OSName { get; }

    private static string OSVersion { get; }

    private static string RuntimeIdentifier { get; }
}

OperatingSystemPlatform is already accessible through IsOSPlatform(Platform). RuntimeArchitecture is already exposed as ProcessArchitecture. The RuntimeVersions proposal is already covered by dotnet/coreclr#22664 and doesn't require an api review.

I chose OS over OperatingSystem as we already use OS in IsOSPlatform.

Thoughts?

@loop-evgeny
Copy link

Why is "RuntimeVersions" plural? Can an app be using multiple runtime versions? If so, how?

Also, please don't make the users parse the actual version number out of a string like "NETCore.App 1.0.4". It's better than nothing, of course, but it would be great to get a System.Version object here.

@ViktorHofer
Copy link
Member

RuntimeVersion is not part of my api suggestion as it's already covered by dotnet/coreclr#22664 and does not need an api review.

@eerhardt
Copy link
Member

@ViktorHofer - I believe this and dotnet/corefx#31002 are duplicates (or very, very closely related).

For sure, your proposal above is an exact duplicate of dotnet/corefx#31002 (except for your proposal has private instead of public, and dotnet/corefx#31002 spells out OperatingSystem instead of OS).

Since dotnet/corefx#31002 already has discussion on that exact API, let's use dotnet/corefx#31002 for that API proposal. If this issue has other proposed APIs, let's use this one for those. If not, I think we could close this issue in favor or dotnet/corefx#31002.

@ViktorHofer
Copy link
Member

Sounds good.

Duplicate of https://github.com/dotnet/corefx/issues/31002

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Runtime
Projects
None yet
Development

No branches or pull requests