Solved

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

Posted on 2009-04-01
4
187 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host asp.net pages 5 25
Syntax Error 2 45
What .NET URL re-routing tool did I use? 2 36
SQL Exceptions 3 37
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

22 Experts available now in Live!

Get 1:1 Help Now