Solved

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

Posted on 2009-04-01
4
186 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
yes i meant that only
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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