Search code examples
visual-studio-2010buildconstantsconditional-compilation

How do you define constantname for #IfDEF (VS 2010)?


I want to add conditions to show certain layout/theme based on build, for example:

I want to define a constant for 2 apps (both debug and release)

#IFDEF APP1.Debug   
   --- display layout 1
#IFDEF APP1.Release
   --- display layout 2
#IFDEF  APP2.Debug
   --- display layout 3
#IFDEF  APP2.Release
   --- display layout 4
#ELSE
  --- display layout 5
#ENDIF

How do setup the constant names (above) in Visual Studio 2010? How do they show up under DEBUG and RElease?


Solution

  • Something like this should work under MSVC:

    #if __PROJECT__  == "App1"
      #ifdef _DEBUG
        #define LAYOUT Value1
      #else
        #define LAYOUT Value2
      #endif
    #elif __PROJECT__ == "App2"
      #ifdef _DEBUG
        #define LAYOUT Value3
      #else
        #define LAYOUT Value4
      #endif
    #else
      #define LAYOUT Value5
    #endif