Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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
Developer Community or GitHub 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.
If would be very useful for writing cross-platform libraries if MonoTouch could define conditional compilation symbols. For example, in Mono For Android it defines __ANDROID__, and then other symbols based on the target API level, such as __ANDROID_10__. If possible, these should be applied to both applications and class libraries.
MonoTouch itself does not compile the code. The MonoDevelop iPhone addin is calling `smcs` to do the job and it's where any additional define can be added.
IIRC one was added for SIMULATOR a while ago.
I have never liked the idea of adding these symbols to the compilation, but they seem to be a pretty common request.
If we decide to add these, we could not add those to the Mono C# compiler as the next version of the compiler will be unified, so we should look into adding the following:
API levels sound like it is taking this a bit too far.
Michael, how could we add this to the iPhone and Android projects?
There are two ways we can do this:
a) have hardcoded defines injected by the build system
b) add the defines to the configurations of each project we create
If we want them version-dependent, then (a) would make sense. It would also affect existing projects. I suppose that would also make more sense for double-underscore "internal" defines. However, implementing this for MonoTouch would currently require a small amount of work on MD core. For xbuild/android it's much easier.
We do currently have support for (b). added by Alan IIRC. It has the advantage that it's more visible to the user, since they can see the defines in the project options.
*** This bug has been marked as a duplicate of bug 5054 ***
I committed a patch to the IPhone's project build logic to modify the (cloned) Configuration by adding __MOBILE__ and __iOS__ just before it gets passed off to the Compile step, if they aren't already defined (so that we can always add them to the project configuration later, if we decide we'd rather do that).
The basic approach looks good but the patch is bad. It will cause an invalid cast for all other project types.
We have verified this issue with the latest builds:
And now under the option C#, Android is appearing for the Android templates and iOS is appearing for the iOS templates.
Hence, closing this issue.
I think there is some confusion about verifying this. This is not about templates. It's about the __MOBILE__ and __IOS__ defines being passed to the compiler. You can verify this by checking that this code is executed successfully in an iOS project:
Console.WriteLine ("__MOBILE__ is defined");
Console.WriteLine ("__IOS__ is defined");