If you have developed some Xamarin applications in the past, you might have stumbled on the excessive range of configuration options you can choose from. The settings you’re using in development may be very different from your Release settings. For example; you don’t want to include debug information in the app that will be published to the App Stores. It will increase the app size enormously and expose technical info about your app that might be useful to malicious people.
Besides the difference of Release and Debug configurations, you sometimes need a extra set of configurations. Visual Studio allows you to create additional build configurations:
![Configuration Manager](https://basdecort.wordpress.com/wp-content/uploads/2017/04/screen-shot-2017-04-24-at-19-24-26.png?w=788&h=252)
Configuration Manager
![Build configurations](https://basdecort.wordpress.com/wp-content/uploads/2017/04/screen-shot-2017-04-24-at-19-24-11.png?w=788&h=496)
Build configurations
Compiler flags / Conditional compilation symbols
Per build configuration you can also specify a set of compiler flags. Compiler flags on itself don’t have any impact on your app, but you can use these flags in your code. By default the build configuration called Debug, has a compiler flag called “Debug”. In your code you can check if this flag is set (and therefor Debug configuration is active) and execute some Debug code. A common scenario is to Log additional information when the Debug flag is set.
![Compiler flags](https://basdecort.wordpress.com/wp-content/uploads/2017/04/screen-shot-2017-04-24-at-19-28-19.png?w=788&h=204)
Setting compiler flags
Using compiler flag in code:
#if Debug InitializeUiTests(); #endif
Related links:
- MSDN – Build configurations: https://msdn.microsoft.com/en-us/library/kkz9kefa.aspx
- MSDN – Conditional compilation symbols: https://msdn.microsoft.com/en-us/library/aa691095(v=vs.71).aspx
One thought on “Build configurations and compiler flags”