473,657 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

different values for debug and release

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
3 2951
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****@newsgro ups.nospamwrote in message
news:A2******** *************** ***********@mic rosoft.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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3199
by: nfr | last post by:
Default build directories seem to be somewhat different between C# and Visual Basic.NET. Both have "Debug" and "Release" directories under "obj". However, Visual Studio.NET defaults to a single "bin" directory whereas C# appears to duplicate the "Debug"/"Release" pattern under bin. This is creating problems for me in regards to browsed "References" added to a project. With C# I need to pick one, which is going to be bin/Debug during...
2
3949
by: Scott Yost | last post by:
I reference a .NET DLL to import some of my custom types. I can build that DLL in debug or release mode, but I usually keep the debug one built so I can debug it. When I want to link to the release version of the DLL, I find that I have to remove the reference from the project and point VS. NET to the release version of the DLL. Is there some way to do this automatically, like it usually done in the past, so that the release/debug switch...
9
1992
by: dee | last post by:
Hi I'm about to upload my site and I have switched to release version. Is that enough or do I still need to disable <compilation defaultLanguage="vb" debug="true" /> the debug="true" in the .pdb file? Is the .pdb necessary for the release version? Thanks a bunch. Dara
0
1525
by: Shawn Hogan | last post by:
I'm getting two different results when I call System.Reflection.Assembly.GetCallingAssembly when compiling in Release and debug modes. When i compile my application using the "Debug" configuration my call to GetCallingAssembly returns the assembly name of the project that contains my form and class(as expected). When i compile using the "Release" configuration GetCallingAssembly unexpectedly returns System.Windows.Forms. Below is some...
3
2189
by: | last post by:
Since I need to dotfuscate my exe file anyway, does it make any difference if I use Debug or Release versions. Would a Debug version be easier to decompile/study/reverse engineer than a Release version, both having been dotfuscated by the standard dotfuscator of visual studio 2003 ? Tia
8
2160
by: Bruce | last post by:
I am using VB in Vs2005. Am I missing something or does VB not have the concept of "builds" (release/debug) like in VC? I wrote an assembly and I would like to have a debug version of the DLL and a release version of the DLL. I would like to create some sample code that demonstrates my assembly in VB and would like to have two builds, one using my debug version and the other using the release version of the assembly. How can I do...
6
9134
by: Andrew Rowley | last post by:
I am having trouble getting debug and release builds to work properly with project references using C++ .NET and Visual Studio 2003. I created a test solution, with a basic Windows form C++ project. I then add a class library, and add a reference to this project in the first project. When I do a release build, I see the following in the output from the DLL compile: /OUT:"C:\Documents and Settings\Andrew\My Documents\Visual Studio
3
1982
by: TBass | last post by:
Hello, Is there a way to get Visual Studio 2003 look to one directory for debug version dlls when set to DEBUG and then to another directory where I store the release version of a dll when set to RELEASE? My current project uses about 8 dlls I've written in the past, but I don't want to keep re-compiling them for debug/release depending on whether I'm compiling the current project for debug/release.
3
1337
by: =?Utf-8?B?UHJpeWE=?= | last post by:
Hi, When i execute application in debug mode it works but on release mode the session values in the website is lost. I use windows server 2003 and IIS 6. It is a 5 step enrollment process whose values are carried forward across pages. It throws error "object reference not set to instance of object and points to session values" when moving across pages in release mode. Pls advise. Thanks Priya
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.