How to define a constant globally in C# (like DEBUG)

前端 未结 4 812
野性不改
野性不改 2020-12-18 20:13

I want to compile a project differently, according to a constant defined by #define, like this:

#define USE_COMPONENT_X

#if USE_COMPONENT_X
...

#endif
         


        
4条回答
  •  臣服心动
    2020-12-18 20:47

    You may want to go a step further and create different project configurations as variants of the standard Debug and Release project configuration. The Configuration Manager under the build menu will let you accomplish this. Then while you are in the project properties' Build tab you can select the various configurations and set the conditional compilation constants that are appropriate for each configuration. This will save you lots of time when you want to swap back and forth between various permutations of your conditionally compiled code.

提交回复
热议问题