Is it possible to differentiate between operating systems in C#
using preprocessor
? like :
#if OS_WINDOWS
//windows methods
#elif O
No. Sadly you can't. And it is even logical: if you compile for AnyCPU
, then your program is executable on any platform.
What you can do is create multiple project configurations, where you set the #define
you want (in the Properties of the project, Build, Conditional compilation symbols).
But perhaps this is a XY problem... Normally you don't need to do it, and you can live with a
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
}
else if (Environment.OSVersion.Platform == PlatformID.MacOSX)
{
}
else if (Environment.OSVersion.Platform == PlatformID.Unix)
{
}