By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,611 Members | 1,642 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,611 IT Pros & Developers. It's quick & easy.

different values for debug and release

P: n/a
Hi.
I was wondering if it was possible to give a variable different values
depending on if the code was compiled in debug or release?

i.e. if the code was compiled in debug:
string strConnection = "Server1";
if the code was compiled in release:
string strConnection = "Server2";

Thanks!
Apr 16 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
A better option might be a configuration file (app.config) or possibly
command-line arguments
Not a good answer, but:

#if DEBUG
string strConnection = "Server1";
#else
string strConnection = "Server2";
#endif

"eladla" <el****@newsgroups.nospamwrote in message
news:A2**********************************@microsof t.com...
Hi.
I was wondering if it was possible to give a variable different
values
depending on if the code was compiled in debug or release?

i.e. if the code was compiled in debug:
string strConnection = "Server1";
if the code was compiled in release:
string strConnection = "Server2";

Thanks!

Apr 16 '07 #2

P: n/a
Hi,

Your objective can be achieved using conditional compilation in C#:

#2.5.4 Conditional compilation directives (C#)
http://msdn2.microsoft.com/en-us/lib...99(vs.71).aspx

#Compiling Conditionally with Trace and Debug
http://msdn2.microsoft.com/en-us/lib...75(VS.71).aspx

If you're using VS2005 to create your C# project, you will see following
settings in the project properties dialog (in the Build tab):

* Define DEBUG constant
* Define TRACE constant

By default, both the DEBUG and TRACE option are checked for the Debug build
configuration, and only TRACE is checked for the Release build
configuration.

Therefore, you can use following code:

#if DEBUG
string strConnection = "Server1";
#else
string strConnection = "Server2";
#endif
Also, VS2005 code editor will gray out the #else part if you're in Debug
mode.

Hope this helps.
Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 17 '07 #3

P: n/a
Thank you very much...this is just what I was looking for.
Will make my code look a little ugly...but it`s a small price to pay for not
rewriting values everytime I need to compile in release :)

Apr 17 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.