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
Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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