'C# compiled in mono - Detect OS
I am trying to get a C# app running under OSX which is not exactly pain free. To work around some of the issues in the short term, I am thinking of setting up some specific rules when it is running in OSX.
But... What can I use to determine whether the app is running under Windows or OSX?
Solution 1:[1]
I know this is an old question but this worked for me:
//using System.IO
public static string GetOS(){
if (Directory.Exists("C:\\Windows")) {return "Windows";}
if (Directory.Exists("/System/Applications/Utilities/Terminal.app")) {return "macOS";}
return "Linux";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Samarth Pradeep |
