2

In .NET Standard 2.0, do I have any ways of determining the operating system and architecture on which my library is running ?

I need to know the OS and architecture to determine which version of nodejs to extract and run at run-time.

Edit about comments : I already found the two methods that you offer but, according to the documentation OperatingSystem.Version and Environment.OSVersion supports the following .net version (standard 2.0 isn't included it seems)

OperatingSystem.version Environement.OSVersion

edit 2 - not a duplicate : As per my first edit above, my question targets .NET Standard 2.0, not .NET Framework or .NET Core. .NET Standard 2.0 is crossplateform byt this page only lists windows version which is a very good way to know that this cannot match my needs.

Athari
  • 33,702
  • 16
  • 105
  • 146
Mathieu VIALES
  • 4,526
  • 3
  • 31
  • 48
  • 1
    See [System.Environment.OSVersion](https://msdn.microsoft.com/en-us/library/system.environment.osversion(v=vs.80).aspx) – xmojmr Oct 03 '17 at 06:51
  • 1
    Possible duplicate of [Detect Windows version in .net](https://stackoverflow.com/questions/2819934/detect-windows-version-in-net) – xmojmr Oct 03 '17 at 07:05
  • It looks like the [second answer](https://stackoverflow.com/a/2819974/6838730) on the "possible duplicate" answer might solve my problem. I'll try it in more details and let you know. – Mathieu VIALES Oct 03 '17 at 07:37
  • This would also mean that the documentation is not up-to-date regarding the APIs available in .NET Standard – Mathieu VIALES Oct 03 '17 at 07:38

4 Answers4

2

After further research and a better understanding of the Environment.OSVersion property, I now know that this question is, in fact, a duplicate of this one.

What led me to believing it was not is that, since the documentation doesn't show that these properties and methods are available in .NET Standard 2.0 i assume they were not and didn't take the time to try it.

So I simply copy/pasted the code from the second answer and saw that no error was thrown ...

Mathieu VIALES
  • 4,526
  • 3
  • 31
  • 48
2

RuntimeInformation.IsOSPlatform(OSPlatform.Linux) RuntimeInformation.IsOSPlatform(OSPlatform.OSX) RuntimeInformation.IsOSPlatform(OSPlatform.Windows)

Hanabi
  • 577
  • 4
  • 9
  • This answer would be improved by adding some explanation of why you recommend `RuntimeInformation` as a better solution. – glenatron Apr 08 '22 at 15:05
1

I found this after looking around abit:

https://msdn.microsoft.com/en-us/library/system.environment.osversion(v=vs.110).aspx

BLANKhttps://msdn.microsoft.com/en-us/library/system.operatingsystem.version(v=vs.110).aspx

edit: Found another resource that I think is what you're looking for:

https://code.msdn.microsoft.com/How-to-determine-operating-c90d351b

banksdev
  • 198
  • 1
  • 1
  • 8
0

RuntimeInformation has the data for the architecture and you can test, if you are on Windows or another OS.

Lars
  • 6,421
  • 1
  • 23
  • 24