views:

193

answers:

3

Sorry if my terminology is wrong. I wrote #if TEST_APP in my code. Now i would like to define TEST_APP. How do i set it using visual studios 2010? This is a windows form application.

Bonus if you can tell me the name of the symbol that is set in a winform project and in a web project

+3  A: 

In the Build tab of the properties page for the project, look for the "Conditional compilation symbols" setting.

I don't believe there are any different symbols defined by default for web and winform applications. Bear in mind this is set for the project itself, and won't affect any class libraries - so I'd expect any code within a project to really know whether it's in a Windows application or not to start with. What were you thinking of using this for?

Jon Skeet
after writing APP_TEST -dAPP_TEST (i am thinking gcc) and them fail and after seeing these answers i realize i had a reference to my web lib instead of including my files. oops. That was when i tried getting F# and C# to define methods in the same partial class.
acidzombie24
I dont need the app and web define, i just wondered since i know C++ does it. I am testing some backend code in an app so i can modify it on the fly which i cant do in a web application (Changes are not allowed in the following case. Debugger attached to an already running process)
acidzombie24
We used this in a webapplication to enable caching in debug. In Release caching logic was enabled, in debug disabled but sometimes you want to test caching logic (in debug). For this is an extra conditional is handy. (DEBUG | DEBUG_WITH_CACHE)
bob
+1  A: 

In visual studio solution explorer, right click on a project and click Properties. Open teh build tab and you will see a field "Conditional compilation symbols". This is a comma separated list. There are also 2 checkboxes for commonly used symbols, DEBUG and TRACE.

For your web projects you could set teh field to "WEB_PROJECT" and winforms to "WINFORMS_PROJECT"

Russell
A: 

Method 1:

#define TEST_APP true
#if TEST_APP == true
#endif

Method 2:

#define TEST_APP
#if defined(TEST_APP)
#endif

Source: MSDN

LnDCobra