?
Solved

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

Posted on 2009-04-01
4
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 1000 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 1000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

741 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