How do I make a conditional compilation statement for release builds in VB.NET? - vb.net

I have some code that I want to skip if we're running a debug build (it's supposed to send an email but that requires an email server which is not available when debugging).
I tried all of these:
#if !DEBUG
#if RELEASE
#if not DEBUG
but all of them misbehaved (the code was either grayed out for a release build or not grayed out for a debug build).
I even tried
#if DEBUG
' dummy blank block
#else
' code goes here
#end if
but the code in the else section is always highlighted, even when I'm in debug mode...
What is the proper way to do this?

When switching to debug mode Visual Studio grayes the Else part because It wants to tell you that you are not in release mode that's why when you switch to release mode it grayes the first part because you're not in debug mode that's all
that was meant to help developpers (I don't know why you can just look up in the selected mode)
Dim blnDebuggin As Boolean = False
#if (DEBUG)
blnDebuggin = true
#else
blnDebuggin = false
#endif
You can also use this to identify the application running mode
System.Diagnostics.Debugger.IsAttached
and i hope this one should work too
HttpContext.Current.IsDebuggingEnabled
Taken from here [Click me ^^][1]
[1]: https://forums.asp.net/t/1552928.aspx?How%20to%20know%20whether%20application%20is%20in%20release%20or%20debug%20mode%20using%20vb%20net%20code

Related

#if DEBUG isn't work on some device for TestFlight version

The below code is work for direct running, but some weird situation occur on TestFlight version. I use Debug build configuration for my archive.
There is a button show on DEBUG mode that is work properly. Tap the button is going to show a table that contains a row and tap the row will perform some action on DEBUG mode. but some weird thing happened the button is show but the row do nothing after tapping. There is a more weird thing. I have a device is work totally fine but other don't.
I have tried to add -DDEBUG on other swift flag but not work.
Any idea welcome.
#if DEBUG
// swift code ...
#endif
#ifdef DEBUG
// objc code ...
#endif
If you want to branch out from your existing project, you need to set up a separate project target.

DEBUG directive not working

In my .NET MVC 4 site I use #If DEBUG Then in a few places. Lately I've noticed that there seems to be some issues with the DEBUG variable. This issue keeps happening
Here is some code I put in a controller action to test my problem:
If DEBUG Then
ViewData("test") = True
#Else
ViewData("test") = False
#End If
If I run my site multiple times alternating between debug and release modes, at first the code will work but after a few tries, the code block above will get stuck into thinking it's in release mode or get get stuck into thinking it's in debug mode. At this point it doesn't matter if I'm in debug or release mode, the stupid thing will cling to whatever value it got stuck on and go to the code block for that value.
In release mode the = True line is greyed out. In debug mode the = False line is greyed out. So that works. But the code might still run a greyed out line if that code corresponds to the value the code is stuck on.
Things that don't fix it:
-alternating some more
-restarting VS
-restarting computer
-unloading project
The only thing that seems to fix it is changing the conditional statements or adding more #If DEBUG Then code somewhere else. It's as if the compiler doesn't reread the conditionals until something changes. This only happens on one VS project I'm working on and doesn't happen for other projects.
This may be something that you left out of your paste but in the first IF you are missing # it should be #If Debug instead If Debug.

Preprocessor target checking

I want to use preprocessor commands to test which target I'm compiling for.
Every example I read told to do that :
Add a preprocessor macro in my target.
Do this :
#ifdef TARGET_NAME_MACRO
NSLog(#"TARGET_NAME");
#else
NSLog(#"ANOTHER_TARGET");
#endif
However, it isn't working. This condition passes whenever I do it in my TARGET_NAME's file but never passes when doing so in another target's file.
I need to test in another target's file if I'm running it in Test mode.
I've tried a few things, none worked out.
Any ideas?

Why is my xcode jump to assembly view when break point set?

When I try to debug with breakpoint, it jump to assembly view like this no matter which line of code. I want the highlight of current source line back!!
How can I config it??
This is a useful feature sometimes, but is easy to turn off:
Debug > Debug Workflow > Always Show Disassembly
In older versions of Xcode (<6.1):
Product > Debug Workflow > Show Disassembly When Debugging
I'm having the same issue in Xcode 6.1 and solved it by doing the following:
Debug -> Debug Workflow -> UNCHECK Always Show Disassembly
Make sure "Always Show Disassembly" is unchecked
You can try this
Product > Debug > Create Symbolic Breakpoint
I agree with humphriesj regarding "Always Show Disassembly" in Xcode 6.1, and it did work for awhile.
But for me it seems to have turned itself back on, even though it was still unchecked in the menu. I turned it on and then back off, and finally I can see the source code again.

Editing VB.net code without stopping executable

I need to be able to edit vb.net code using visual studio without stopping the debugging executable.
How can I go about doing this? If it's impossible, how can I code and reload that code without stopping the executable? I know of scripting languages like Lua, but I fear the implementation of another language within the VB is unnecessary to save me the trouble of stopping the executable.
The issue is that starting and stopping this executable can take a very long time, and I need to be able to edit the code quickly and frequently.
I think you're talking about "Edit and Continue" which can be enabled in VS2010 > Tools > Debugging > Edit and Continue.
Note: the application must be in "break" mode to enable editing. When you talk about "Stopping the executable" do you mean stopping all debugging or stopping at a breakpoint?
Edit + Continue has been supported since VS2005. It won't work by default when you run on a 64-bit operating system, only 32-bit code is supported. Easy fix: Project + Properties, Compile tab, scroll down, Advanced Compile Options, change the Target CPU combobox to "x86". That's the default now for new projects created in VS2010.
Not every type of code change is supported by E+C, details are in this MSDN Library page.
Its easy, Edit and Continue is supported from VS1.1 up. The trick is placing a breakpoint in your code by clicking the left margin of a code window on a line of code you wish to halt the program. You will need to run the program in Debug mode (not release mode).
Tip you can also press Ctrl + Alt + PauseBreak to halt the program in the middle of a lengthy operation.
Once the programs Code Control halts you are free to edit and continue.