C# preprocessor differentiate between operating systems

What you are asking for is possible but needs a bit of work.

  1. Define a preprocessor variable in your csproj

    <PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
      <DefineConstants>_WINDOWS</DefineConstants>
    </PropertyGroup>
    
  2. Use that in your code

    #if _WINDOWS
      // your windows stuff
    #else
      // your *nix stuff
    #endif
    

I find this technique useful when you have constants that are dependent on the OS (for example native library names)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)