I am using .NET Core to build a cross platform class library. Depending on the operating system that the C# .NET Core project is built for using a .csproj file, I need to co
For differentiating between Windows & Mac/Linux you can use the $(os) property: this gives you Windows_NT for Windows and UNIX for Mac/Linux.
For differentiating between Mac & Linux, at least on recent versions of MSBuild, you can use RuntimeInformation.IsOSPlatform.
So, combined, your csproj can have something like this:
PreserveNewest
PreserveNewest
PreserveNewest
To the best of my knowledge, this should work in all recent versions of .Net Core, Mono and .Net Framework.
In older versions, you'd need to resort to evil trickery for differentiating between Mac & Linux:
For Linux -> Condition=" '$(OS)' == 'Unix' and ! $([System.IO.File]::Exists('/usr/lib/libc.dylib')) "
For Mac -> Condition=" '$(OS)' == 'Unix' and $([System.IO.File]::Exists('/usr/lib/libc.dylib')) "
Sources: