Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically check the build configuration

Using the DEBUG configuration, I can switch behaviour on and off using this type of syntax:

#if DEBUG
    Console.WriteLine("Debug");
#else
    Console.WriteLine("Not Debug");
#endif

However, if I set up a different configuration, say: TEST then this doesn't work:

#if TEST
    Console.WriteLine("Test");
#else
    Console.WriteLine("Not Test");
#endif

Is there a way to check these?

like image 896
Paul Michaels Avatar asked Jul 15 '16 12:07

Paul Michaels


People also ask

How do I get build configuration in Swift?

Adding a Configuration Fire up Xcode and create a new project by choosing the Single View App template from the iOS > Application section. Name the project Configurations, set Language to Swift, and make sure the checkboxes at the bottom are unchecked. Tell Xcode where you'd like to store the project and click Create.

What is build configuration?

A build configuration is a collection of settings used to start a build and group the sequence of the builds in the UI. Examples of build configurations are distribution, integration tests, prepare release distribution, "nightly" build. A build configuration belongs to a project and contains builds.

What are debug and Release build configurations?

A Debug configuration supports the debugging of an app, and a Release configuration builds a version of the app that can be deployed.


1 Answers

Yes you can use different configurations. DEBUG symbol is generated automatically if you choose Debug configuration in your configuration manager. You can check it. Go to Your project -> Properties -> Build -> Define DEBUG constant

If you need to use additional constant just enter your own in Conditional compilation symbols.

Steps for your case:

  1. Go to Your project -> Properties -> Build
  2. Switch configuration to Test
  3. Enter TEST to Conditional compilation symbols field

Run your code and enjoy :)

like image 193
eldrex Avatar answered Sep 28 '22 09:09

eldrex