In this article I will show how to check whether application/ solution is in debug mode or in release mode.
Everytime we deploy application code on live/production environment, we want to change certain settings like database connection, email settings etc. Production settings are always different then what we use at development/local environment. For this we use application configuration setting. We keep separating settings for debug and release mode in web.config file where generally we have separate files for both. We can add our custom mode also but that we can discuss later. This was about how we can change settings through web.config file. Now suppose in code behind we are writing two set of code and we want that on run time application should find whether it is in debug mode or release mode and should execute the code set accordingly. We can do this very easily. Let's see how we can check this.
To identify whether application is in debug/release mode, we can use pre-defined system variable DEBUG or RELEASE. We can simply put a check and can execute respected code. One thing I want to add here is that if application is in debug mode then deug part in condition will be active and else part will be gray and vice versa. This is very quick way to check that in current configuration setting which part of code will execute.
#if DEBUG
Console.Write("This part will execute when application configuration is set to debug mode.");
#else
Console.Write("This part will execute when application configuration is set to release mode.");
#endif
See this was so simple to use. So use it and enjoy. You can set your code accordingly. I will come back with another such tips