crazy_p
crazy_p

Reputation: 310

#if DEBUG and Conditional(“DEBUG”) called in Release build

I have a method that sets up some Debug only configurations, I have used this pattern on a few projects and with some of them it seems that nor #if DEBUG nor Conditional("DEBUG") are omitted in my release build.

Any ideas why?

Define DEBUG constant is checked: enter image description here

Upvotes: 1

Views: 980

Answers (2)

crazy_p
crazy_p

Reputation: 310

Something that may be obvious for some: the Build configuration changes based on the selected Configuration (eg. Debug) and Platform (eg. Any CPU).

In order to have #if DEBUG and Conditional("DEBUG") working as expected, the DEBUG constant must be defined in the 'Debug' configuration only!

Notice the difference:

Debug:
enter image description here

Release:
enter image description here

If DEBUG is defined in Release, when using #if DEBUG or Conditional("DEBUG"), the condition will return true because the DEBUG constant exists in the project configuration.

Upvotes: 0

bizzehdee
bizzehdee

Reputation: 21003

As stated by @Evk, ""Define DEBUG constant" is checked. You need to uncheck it".

That defines DEBUG for the preprocessor even if it is not in the text box above it

Upvotes: 2

Related Questions