Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compiler directive, conditional compile.

Status
Not open for further replies.

tgreer

Programmer
Oct 4, 2002
1,781
US
I'm writing an application that must get certain values passed in via environment variables. (Yeah, I know about app.config, but the customer requires I integrate the app into a workflow where they use batch files to set environment variables.)

When debugging, these variables of course are not set, so I hardcode them. I can forsee myself forgetting to comment-out these lines. Is there a compiler directive to conditionally compile code segments? I can see that through the Configuration Manager, there is a "debug" environment. Can that be used to say "if (debug)"?

Or, is there a better way to manage this situation?



Thomas D. Greer
 
The conditional compilation directives are similar to those in C/C++

#if
#else / #elif
#endif

So you'd do a #if debug [...] #endif

It's probably case-sensitive.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Well, that isn't quite it. My "#if (DEBUG)" always evaluates to true, even when I'm not debugging. I guess I don't quite know how to use the Configuration Manager.

I see two Configuration profiles, "Debug" and "Release". There are constances I can define for both of them. The constant I want in the "Debug" configuration is "DEBUG". Ok so far.

However, apparently I need to make the proper Configuration "active" each time I compile. That's what I wanted to avoid. If I have to remember to do that, then I might as well remember to comment-out the code segment in question each time I compile.

I don't see how the compiler-directive SAVES me any steps. Either remember to comment-out code, or remember to switch Configuration.

Thomas D. Greer
 
However, apparently I need to make the proper Configuration "active" each time I compile.

Yes, that's how Microsoft has had it designed since Visual Studio 5, at least.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
I missed all of that. I haven't used a Microsoft IDE since VB 3.0.

I understand the need to differentiate between a Debug and a Release version. However, I need to further differentiate between a "Debug" version being run inside (actively debugging) and outside of Visual Studio.



Thomas D. Greer
 
When debugging, these variables of course are not set

why would that be, then? is your pc locked down?

even if it is, you can set system-wide temp variables.

you could even do it from a batch file ;)

mr s. <;)

 
It looks as if your managed program is being debugged by a managed debugger (.net debugging another .net program), there's no way to tell this. If it were a win32 debugger, yes. But running a win32 debugger against a managed executable would be extremely painful.


Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top