Disable MVC compilation debugging for releases
I have three config files for my MVC 5. project web.config
, web.debug.config
and web.release.config
.
I want to disable compilation debug
on startup in release, but cannot get it to work.
In web.config
<compilation debug="true"/>
In web.release.config
<compilation debug="false"/>
When I run in release mode HttpContext.Current.IsDebuggingEnabled
it is still equal true
(still attached to the debugger).
What am I doing wrong? I tried to take the tag out of the main one web.config
and put it in web.debug.config
, but the debugger just complained and asked to put it back inweb.config
Update
My web.release.config looks like this
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/error/notfound" responseMode="ExecuteURL" />
<remove statusCode="403" />
<error statusCode="403" path="/error/forbidden" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--<compilation debug="false"/>-->
</system.web>
source to share
In web.config
:
<compilation debug="true" ...
In web.release.config
:
<compilation xdt:Transform="RemoveAttributes(debug)" />
This will set transform
in the attribute debug
in the tag compilation
, for remov
. You don't need to set any transform to web.debug.config
because you don't want to change the configuration in debug mode.
After that publish (deploy) your project. To test it, publish the project to a folder and open there web.config
. You will see that it has web.config
been converted. Config-transforms is a deployment feature.
More information here: http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/web-config-transformations
source to share