0

I building an app, I want to use some value for testing purposes only, so I wrote code similar to this:

#if DEBUG
    public const string AndroidCeneamStaticBannerTest = "ca-app-pub-3940256099942544/6300978111";
    public const string AndroidCeneamInterstitialBannerTest = "ca-app-pub-3940256099942544/1033173712";
    public const string AndroidCeneamInterstitialVideoTest = "ca-app-pub-3940256099942544/8691691433";
    public const string AndroidCeneamRewardedVideoTest = "ca-app-pub-3940256099942544/5224354917";
#else

    public const string AndroidCeneamStaticBanner = "ca-app-pub-7822579076265627/3466411993";
    public const string AndroidCeneamInterstitialBanner = "";
    public const string AndroidCeneamInterstitialVideo = "";
    public const string AndroidCeneamRewardedVideo = "";
#endif

now whenever i have debug chosen set at VS2019 the code withing the #if statements remains colored, and the code within the #else statement remains grayed!

well I thought that it would behave like native UWP when you use that code and set VS2019 to Release mode, but in my VS2019 the code within #if Statement remains colored ignoring that I just set the build to release mode, and obviously the code that i was expecting to be colored still grayed.

so my question is the following one: is it possible to execute code in debug mode and execute another code in release mode in Xamarin.Forms??

I would appreciate your help, thanks!!

Jack Zhai
  • 6,230
  • 1
  • 12
  • 20
  • 2
    yes you can, but you need to verify that the compiler symbols are defined correctly in your project options dialog. – Jason Dec 05 '19 at 00:13
  • I dont know how yo define debug symbols could you point me in the bright direction please – Enrique A. Pinelo Novelo Dec 05 '19 at 00:16
  • It's not about your code being in debug mode, it's whether there is a symbol called `DEBUG` defined for the debug/release configuration. It should be that way by default, but it can be easily changed. Check your project properties. See here on how to define it: https://stackoverflow.com/questions/2355340/how-do-i-define-a-preprocessor-symbols-in-c-sharp-visual-studios – DavidG Dec 05 '19 at 00:16
  • 1
    Project Properties, Compiler, Define Symbols – Jason Dec 05 '19 at 01:29
  • but if I write a symbol RELEASE for example, will visual studio know that as soon as i set the build to release will run the code within the #elif RELEASE statement? – Enrique A. Pinelo Novelo Dec 05 '19 at 02:14
  • 1
    there is a dropdown at the top of the dialog where you pick the configuration, so you can edit the symbols per-config – Jason Dec 05 '19 at 03:09
  • Thanks Jason, I had just realize how to use the build window of each project. Please write your answer to the question, so I can upvote for your solution. you were very helpful!! – Enrique A. Pinelo Novelo Dec 05 '19 at 15:07

1 Answers1

1

Yes, it is possible. But there are some settings about build directives that you should make in the solution and not just in the projects.

enter image description here enter image description here