andreyk2 Hohlov
andreyk2 Hohlov

Reputation: 749

.NET Core "RuntimeInformation.OSDescription" property under the hood (and .Net Core Multi-Platform support implementation in general)

After investing ~8 hours on endless search around the google, I have to ask you guys here on the community. Pls help :-)

This is theoretical Q, and I want to understand how this "magic" implemented by Microsoft .Net Core CLR. While I understand how to implement my own code to be able to work on different OS (by using Interface and P/Invoke of specific platform) from the answer: https://stackoverflow.com/a/52297584/10696080

I don't understand how the .Net Core CLR DLLs implements the same functionality. For "RuntimeInformation.OSDescription" or "RuntimeInformation.IsOSPlatform" for example.

By looking on the source code of .Net Core RuntimeInformation class it looks like is not implemented by Interface and P/Invorke , but by some mysterious method.

My findings till here:

  1. I find more general question: .Net Core Multi-Platform underlying framework implementation But is not answers my Q.

  2. The microsoft site also not explains this

  3. Decompiling System.Runtime.InteropServices.RuntimeInformation.dll reveal only empty static properties

Question: Pls advise where can I look for the explanation of how the .Net Core CLR DLLs implements multi-platform support (ot more specifically, how RuntimeInformation.OSDescription works)

Upvotes: 0

Views: 894

Answers (1)

andreyk2 Hohlov
andreyk2 Hohlov

Reputation: 749

.Net Core CLR DLLs implements multi-platform support implemented by:

  1. .NET Core source code has target specific OS preprocessor directives:

    *#if TARGET_WINDOWS ...

    #elif TARGET_OSX ...

    #elif TARGET_UNIX ...*

  2. Conditional compilation is done and DLL compiled separately for each target platform. So there are some versions of .NET Core DLLs (in the .NET Core SDK)

  3. While deploying the app:

    A. Fremework dependent deployment. Your app uses the OS specific DLL version, which already installed on the target machine (in .NET Core runtime)

    B. Self contained deployment. Platform specific DLL taken from SDK and included in the application folder

Upvotes: 1

Related Questions