Tip: Different Aspects to Detect the Platform of the dotNET Runtime Environment

In the context of cross-platform development it could be possible to differentiate at runtime on which platform the execution environment runs. In my first approach I use the method RuntimeInformation.IsOSPlatform, but this is only available with dotNET Framework >= 4.7.1. So it is not possible to build an assembly for the UiPath Windows-Legacy compatibility mode. As an alternative it is possible to use Environment.OSVersion property, with the PlatformID enumeration.

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
  // Here your Windows code
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
  // Here your Linux code
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
  // Here your MacOSX code
}

Code which works only in dotNET >= 4.71

if (platformId == PlatformID.Unix) {
  // Here your Linux or MacOSX code
} else if (platformId == PlatformID.Win32NT) {
  // Here your Windows code
}

Code which works in all releases of dotNET

It is probably only a matter of time before we can do without the building of Windows-Legacy assemblies. However, until then this may be a viable way.