How to set debug false for release mode

Possibly an improvement to Omar.Alani's answer:

In the Release transform, replace the line:

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

with the following:

<compilation debug="false" xdt:Transform="SetAttributes" />

If you'd like to test your .NET bundling and minification that you've got set up in your Global.asax file, you can also use precompilation notation...for example

#if DEBUG
  BundleTable.EnableOptimizations = false;
#else
  BundleTable.EnableOptimizations = true;
#endif

With this, your application won't need to trigger the transform in the build operation and will run just like you want it to.


My answer might be late, however this what worked with me:

I've changed the line :

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

to :

<compilation xdt:Transform="Replace" debug="false" targetFramework="4.5" />

this basically did the trick, as I think the optimizer is looking for Debug value to be be present and == "false".

Hope this helps people who don't want to manage this from code.


Web.config transformations as they are defined in the Web.Release.config are only done when deploying/publishing the project for the relevant configuration.

Just changing the active configuration in Visual Studio to Release and running the application does not run the transformations. Therefore, the web.config remains unchanged. This behavior is reasonable by the way as a web application is run from the project directory that contains the original web.config. If Visual Studio were to transform the web.consign, your original web.config would be changed.

If you haven't created a deployment profile yet, you can publish your application to the file system to verify the behavior. Choose Release as the configuration to run the deployment for. The transformations should be executed as expected.