Bug 15974 - ($OS) conditionals do not support "OSX" yet
Summary: ($OS) conditionals do not support "OSX" yet
Alias: None
Product: Tools
Classification: Mono
Component: xbuild ()
Version: unspecified
Hardware: PC Mac OS
: Low minor
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2013-11-06 14:53 UTC by David Evans
Modified: 2013-12-04 13:54 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description David Evans 2013-11-06 14:53:00 UTC
Take this PropertyGroup example:
<DefineConstants Condition=" '$(OS)' == 'OSX' ">MACOS;MONO;DEBUG;TRACE</DefineConstants>

The OS code in the latest mono file still has this, which means we never see 'OSX' in xbuild, only 'Unix':
from mcs/class/corlib/System/Environment.cs

                /// <summary>
                /// Gets the current OS version information
                /// </summary>
                public static OperatingSystem OSVersion {
                        get {
                                if (os == null) {
                                        Version v = Version.CreateFromString (GetOSVersionString ());
                                        PlatformID p = Platform;
                                        if (p == PlatformID.MacOSX)
                                                p = PlatformID.Unix;
                                        os = new OperatingSystem (p, v);
                                return os;

Two problems from this
1. The documentation here is wrong, it still says I can check for "OSX" which doesn't work with trunk:

2. As a result, there is no way for me to setup conditional properties to differentiate between MacOS and Linux that I can tell, which would be darn helpful in some cases.

So since this isn't a backward compatibility issue that's causing PlatformID to get mapped to Unix, could we instead have the xbuild class in this file instead return the proper value on 'OSX'?

               static string OS {
                        get {
                                PlatformID pid = Environment.OSVersion.Platform;
                                switch ((int)pid) {
                                case 128:
                                case 4:
                                        return "Unix";
                                case 6:
                                        return "OSX";
                                        return "Windows_NT";


Instead of relying upon Environment.OSVersion.Platform how about instead using System.Platform (which does I think return the right ID) or the raw result of Environment.Platform instead?

Comment 1 Mikayla Hutchinson [MSFT] 2013-11-06 15:11:33 UTC
IMO this is unlikely to change as there are targets files in the wild that depend on the current "Unix" value. It's not wrong, anyway, since Mac OS X is a Unix.

Note that Environment.OSVersion.Platform never returns PlatformID.MacOSX anyway, for back-compat reasons. This is really no different. But we should fix the docs, at least.

Anyway, it's definitely possible to set up your own properties, e.g.:

    <IsMac Condition="'$(OS)' == 'Unix' && Exists ('/Library/Frameworks')">true</IsMac>
Comment 2 David Evans 2013-11-06 15:31:15 UTC
There really is utility in some way to differentiate between Unix and Mac in xbuild. e.g. which version of a library to link against. Having different targets is an option, but a simple conditional would also be sufficient if there was one. Perhaps a new value instead of $(OS) to test against that is more precise?

Thanks for that PropertyGroup workaround using the directory existence test. Not as clean but perhaps what I'll have to go with.
Comment 3 Mikayla Hutchinson [MSFT] 2013-11-06 15:35:58 UTC
Sure, but you could make the same argument for any Unix or Linux variant.

Ultimately we're limited to some extent by compatibility with MSBuild, which wasn't really designed with xplat in mind.
Comment 4 Mikayla Hutchinson [MSFT] 2013-11-06 15:37:41 UTC
Although we can't really extend the Common targets and the MSBuild engine much w/o breaking compat, you could always put this in a CrossPlatformHelpers.targets file that you could <Import...> into any project.