Chris
Chris

Reputation: 27394

Turning off MVC compilation debug for release builds

I have three config files for my MVC 5 project. web.config, web.debug.config and web.release.config.

I want to turn off compilation debug when running in release but cannot seem to 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 is still equal to true (still attached to debugger though).

What am I doing wrong? I tried to take the tag out of the main web.config and put it into web.debug.config but the debugger just complained and asked me to put it back in to web.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>

Upvotes: 3

Views: 3549

Answers (1)

Abhitalks
Abhitalks

Reputation: 28437

In your web.config:

<compilation debug="true" ...

In your web.release.config:

<compilation xdt:Transform="RemoveAttributes(debug)" />

This will set the transform on the debug attribute on the compilation tag, for removing it. You don't need to set any transform in your web.debug.config because, you would not want to change the config while in debug mode.

Once done that, publish (deploy) your project. To test it, publish your project to a folder and then open up the web.config there. You will see that the web.config has been transformed. Config-transforms are a deployment feature.

More info here: http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/web-config-transformations

Upvotes: 7

Related Questions