Programmatically check assembly configuration

Using the DEBUG configuration, I can enable and disable the behavior using this type of syntax:

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

However, if I configure a different configuration, say: TEST, then this will not work:

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

Is there any way to test them?

+4
source share
2 answers

The constant DEBUGis special, and for each project in each configuration there is a parameter whether it should be defined. By default, it is turned on DEBUGand off in Release, but it is fully customizable - open the properties page for the project and look in the "Build" section, and there is a checkbox "Define DEBUG constant".

, , . , .

, " " - .

+5

, . DEBUG , Debug . . β†’ β†’ β†’ DEBUG

, .

:

  • β†’ β†’
  • TEST .

:)

+3

Source: https://habr.com/ru/post/1648023/


All Articles