For the debug=true
vs debug=false
discussion, there are many benefits in a production system to turning debugging off when publishing to production. The other answers and comments go more into detail on that (one big advantage that I've noticed in MVC4 apps is that JS and CSS bundles are minified when debug is off).
For the question about is publishing in Release
mode sufficient, please read below:
If you are using the out-of-the-box transformation files that come with a new ASP.NET project, then no, you do not need to manually set it. However, if you don't have transformation files or you're not using them, then when releasing to production, you should change that setting.
Basically, when you publish an ASP.NET web site, what it'll do is build the application, apply the appropriate web.config transformation (based on the configuration selected in the "Settings" portion when using the "Publish Web" feature - which I'm assuming is where you're selecting the "Release" mode), and then publish the code out to the specified location.
Usually, to get you started with transformations, when you create an ASP.NET application in Visual Studio, you will be given two transformations for your web.config: web.Debug.config
and web.Release.config
(you can see them by clicking the expand symbol next to your web.config file).
If you don't have any transformations, you can create them by right clicking on the web.config file and selecting "Add Transform Config" and transformation files will be created for your various build configurations that you have in your solution.
As Maxim Kornilov mentioned in his reply, the out of the box web.Release.config contains this important transformation line: <compilation xdt:Transform="RemoveAttributes(debug)" />
, which tells the application to remove the debug
attribute from the <compilation
tag, which will make the application publish with debugging turned off.
Note: if you don't see that RemoveAttributes(debug)
in the config transformation that you're selecting when publishing, then the code might publish in debug mode.
If you really want to be sure of how the transformation is working, view the contents of the web.config after a publish, and you'll see the output of the transformation
Additionally, there is a tool at http://webconfigtransformationtester.apphb.com/ that will let you test how a web.config transformation will affect your web.config file.
Lastly, I'm a big fan of using a build-server and builds to publish my code when it's ready to go live (less folks need direct access to the server that way), so web.config transformation help me out quite a bit, from allowing me to change connection strings based on the environment that I'm deploying to, as well as to manage warning messages, etc. for the different environments (e.g., warning: test system, don't enter real data). By using transformations, the main collection of settings can stay in the web.config file (along with local dev settings, since hitting F5 usually doesn't apply a transformation, unless you have it publish locally to test), and each environment has its own config transformation that lives in source control, and with the same branch, code can be easily deployed to multiple environments without needing to change any code.