C# forum for web developers

Conditional compilation symbols

Dec 29, 2010 4:27 pm
Alcibiade

Hi guys,

If in my code I write
#if USE_VAR
.....
#endif

I must type or delete the USE_VAR in the conditional compilation symbols
textbox.

Is there a way to keep always the string in the textbox but using it
when I want?
For example if I want to use it I can write

USE_VAR=1 or USE_VAR=true or USE_VAR="1"
on the other hand I 'll use
USE_VAR=0 or USE_VAR=false or USE_VAR="0"
Thanks

Dec 29, 2010 6:50 pm
Peter Duniho
Re: conditional compilation symbols

On 12/29/10 8:27 AM, Alcibiade wrote:
> Hi guys,
>
> If in my code I write
> #if USE_VAR
> ......
> #endif
>
> I must type or delete the USE_VAR in the conditional compilation symbols
> textbox.
>
> Is there a way to keep always the string in the textbox but using it
> when I want?
> For example if I want to use it I can write
>
> USE_VAR=1 or USE_VAR=true or USE_VAR="1"
> on the other hand I 'll use
> USE_VAR=0 or USE_VAR=false or USE_VAR="0"

C# #defines are strictly "defined" and "not defined". If you want a
project-wide definition, you'll have to maintain that explicitly in the
project settings. Note that you can define additional build
configurations, so that some include the definition and some do not.

If the symbol is to apply only in a single source code file, you can
also just define it at the beginning of the file. For example:

#define USE_VAR

Then you can comment it out when you don't want the symbol to apply.
Manipulating the build configuration is more maintainable, but a) can
get out of hand if you're dealing with permutations of multiple symbols,
and b) might be overkill if you're just including the conditional
compilation for prototyping, rather than intending to keep it in production.

Pete




Previous Thread: Re: MVC Application using EntityFramework
Next Thread: TextWriter problem.

Related Forum Topics
Resource DLL generation at compilation stage
I've inherited a C# project written in VS 2005 from a colleague who has
left. There was very little hand-over time. Most things work fine, but one
thing that I'm totally in the dark about is how the Internationalization
DLLs were produced.

On compile, I get an EXE, a few other DLLs and...
Debug-Logging with conditional compile and config options
I have a multi-threaded application with a lot of debug logging. The
logging expressions call functions with [Conditional("DEBUG")], so
release builds are free of the overhead.

Now I need to enable/disable different kinds of log events in the
app.config. Of course, this only applies to...