Вопрос

Is it possible to have some preprocessor directive constants for different files in different projects in visual studio 2010 ? Here is an example of what I'm trying to do:

In file "1" in project "A" I define: TIMEDISPLAYING

 #define TIMEDISPLAYING

in file "2" in project "B" I check for TIMEDISPLAYING:

 #if TIMEDISPLAYING
        //do something
 #else
        //do something else
 #endif

I know in the project file I can add my custom constants. Is there somewhere in the solution file where I can add something similar? Or some other type of file that imports all of my custom constants?

I currently have boolean constants defined in one class, but I would like my code compiled based on the constants and DEBUG is not enough for me. My next solution would be to just add my boolean constants if DEBUG is defined:

 #if DEBUG
           protected const bool ISTIMEDISPLAYING = 1 == 1;

           protected const bool ISDATARANDOM = 1 == 0;

           protected const bool IS_AUTO_LOADING_CHAMP_VENDOR = 1 == 1;

           protected const bool IS_TESTING_PO = 1 == 0;
 #endif

Is there any alternative solution to my last one here? Any help greatly appreciated.

Это было полезно?

Решение

You can set conditional compilation symbols on the Build tab of your project properties in Visual Studio instead of declaring them in the code. Different build configurations can have different conditional compilation symbols assigned, and you can create as many build configurations as you need. This is probably easier to manage, and you don't have to worry about which source file to add them to because they're stored in the project itself.

You might also find the Conditional attribute useful if you wish to include or exclude a whole method based on a conditional compilation symbol.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top