Solved

How do I set different variable values for Release or Debug builds?

Posted on 2009-04-01
4
188 Views
Last Modified: 2013-11-26
I have created a Class Library project to back up my ASP.NET website.  There are certain variables that need to be different depending on whether it is a Debug build, which will be deployed to my testing server, or a Release build that will go on the production server.

Is there some way to have the compiler sense the build type and use the appropriate values for the variables?
0
Comment
Question by:btumer
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 250 total points
ID: 24039094
you can use
#if DEBUG
// set debug version variables here
#else
// set release variables here
#endif

the way its controlled in the asp.net application is through the web.config file
in the config file
for debug version <compilation debug="true">
and for release version <compilation debug="false">
0
 
LVL 8

Assisted Solution

by:rseabird
rseabird earned 250 total points
ID: 24039145
Yes, this is possible. We have also a winforms project and we did it the following way (sorry, it's VB.NET, but you'll got the idea).

On the project properties, you have the COMPILE tab. Here you can manage the configuration settings for debug and release. At the top, you have the configuration dropdown.
Select here the 'Debug' option. After that, press the 'Advanced Compile Options' button at the bottom.
Here you can create your custom constants. We created the following: TESTENVIRONMENT=TRUE
Note: do it only on the debug configuration.

After that, we created a public readonly property at the application events like this:

Public ReadOnly Property TestEnvironment() As Boolean
      Get
            #If TESTENVIRONMENT Then
                Return True
            #Else
                Return False
            #End If
    End Get
End Property

With this, in the application you can check this property whether you are running in debug mode or not.
0
 
LVL 1

Author Comment

by:btumer
ID: 24039315
So in a code-behind file, I can still use the structure
#if DEBUG
// set debug version variables here
#else
// set release variables here
#endif
and it will figure it out based on the  <compilation debug="value" /> in the web.config?
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24039333
yes i meant that only
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now