Recognizing Release vs. Debug

  • Thread starter Thread starter Anil Gupte
  • Start date Start date
A

Anil Gupte

Is there any way to define a variable that recognizes Debug versus Release
versions? Basically, in the two versions, I want to use different
directiories for certain tasks. For example

If (Version is Release)
ContentFilesDir = "C:\Content"
Else
ContentFilesDir =
System.Reflection.Assembly.GetExecutingAssembly().Location()
End If

I know C++ has something like this (IFDEF?), but how do I do it in VB.Net
2003?

TIA,
 
Is there any way to define a variable that recognizes Debug versus Release
versions? Basically, in the two versions, I want to use different
directiories for certain tasks. For example

If (Version is Release)
ContentFilesDir = "C:\Content"
Else
ContentFilesDir =
System.Reflection.Assembly.GetExecutingAssembly().Location()
End If

I know C++ has something like this (IFDEF?), but how do I do it in VB.Net
2003?

TIA,

You can use the System.Diagnostics.Debugger.IsAttached to see if a
debugger is running, or you can use the #If Debug precompiler
statement for if...then blocks as well.

Thanks,

Seth Rowe [MVP]
 
Anil Gupte said:
Is there any way to define a variable that recognizes Debug versus
Release versions? Basically, in the two versions, I want to use
different directiories for certain tasks. For example

If (Version is Release)
ContentFilesDir = "C:\Content"
Else
ContentFilesDir =
System.Reflection.Assembly.GetExecutingAssembly().Location()
End If

I know C++ has something like this (IFDEF?), but how do I do it in
VB.Net 2003?


#if DEBUG then
ContentFilesDir =
System.Reflection.Assembly.GetExecutingAssembly().Location()
#Else
ContentFilesDir = "C:\Content"
#End If

The DEBUG constant is defined in the project properties for the Debug
configuration only. (In VB 2008 Express @ folder Compile -> Advanced
Compile Options...


Armin
 
Is there any way to define a variable that recognizes Debug versus Release
versions?  Basically, in the two versions, I want to use different
directiories for certain tasks.  For example

If (Version is Release)
    ContentFilesDir = "C:\Content"
Else
    ContentFilesDir =
System.Reflection.Assembly.GetExecutingAssembly().Location()
End If

I know C++ has something like this (IFDEF?), but how do I do it in VB.Net
2003?

TIA,

I assign a value of "Debug" or "Release" to the AssemblyConfiguration
attribute depending on the value of the #DEBUG precompiler variable.
That way the assembly is stamped with the information needed to
determine whether what build configuration was active. You could then
pull the value of that attribute at runtime to do what you are wanting
to do.
 
Anil said:
Is there any way to define a variable that recognizes Debug versus Release
versions?

Depends what you mean by "Debug".
No, I'm not kidding.

If you mean ...

"was this executable was /compiled/ in Debug /Mode/?"

.... then use:

#If DEBUG Then
#Else
#End If

On the other hand if you mean ...

"is this executable currently /being/ debugged?"

.... then you need:

If System.Diagnostics.Debugger.IsAttached Then
Else
End If

HTH,
Phill W.
 
Back
Top