In Visual Studio how to add special cases for debug and release versions?

c#, debugging, visual-studio-2010

Solution

Using your example, add some #if / #else / #endif directives like so:

#if DEBUG
    rpg_Admin.Visible = true;
#else
    rpg_Admin.Visible = false;
#endif

You could also apply `System.Diagnostics.ConditionalAttribute` attributes to any code that's only used in the debug version. That will completely remove any unnecessary code from the release build. Example:

[Conditional("DEBUG")]
public static void MyDebugOnlyMethod()
    {
    }

Problem

Possible Duplicate: C# if/then directives for debug vs release I am working on a C# project and I like to know how to add special cases while I am running the program in the debugger in the Debug Mode I have access to certain resources that I would not normally have in the release version. Here is what keeps happening, I have admin tools built into the program, that are just for debugging, like a button that says test and put what ever code I want to into it. What keeps happening I forget to hide that button and I release it to the clients. I would love to have that test button there only while it's running in the debug mode but not any other time. This turns on my admin tools ``` rpg_Admin.Visible = true; ``` This turns off my admin tools ``` rpg_Admin.Visible = false; ``` Is there a simple way to do this? ``` if Debug Mode rpg_Admin.Visible = true ``` or maybe while it's running in visual studio it's ``` rpg_Admin.Visible = true ``` but when it's running on it's own ``` rpg_Admin.Visible = false ``` I am running on Visual Studio 2010 Thanks.

Original source

Related problems