How to set debug false for release mode
S

6

31

I have this web.config file with the compilation option set as below

Web.config

<configuration>
...
<system.web>
    <compilation debug="true" targetFramework="4.5" />
    ...
</system.web>
</configuration>

And here is what Visual Studio puts for release mode by default.

Web.Release.config

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
 <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
 </system.web>
</configuration>

I am using this for MVC4 project. Based on this tutorial, I was expecting that minified versions of js and css would be served, when the application is run under Release Mode. But this doesn't seem to be working and non-minified versions of js and css are being served. On the other hand, if I explicitly set debug to false in web.config, then the min versions are served correctly.

It seems like compilation tag Transform issue when the application is run under Release Mode, but I don't understand what's wrong with the same in Web.Release.config.

In short, I am unable to get bundling and minification working, by running application under Release Mode.

Squeak answered 28/2, 2014 at 4:33 Comment(1)
I bet this is happening because your app is running under a virtual directory of a parent app in IIS and inheriting its config for this when absent, hence why it fixes it when present, overriding the parent config!Nam
S
19

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.

Sartor answered 28/2, 2014 at 5:24 Comment(5)
I was scratching my head for some time now. By the way, where does the visual studio localhost run the site temporarily from. I mean from which directory. Say, when I debug the website using visual studio, I want to check what ends up in web.config.Squeak
@Nirvan: AFAIK when running the app from VS, the development folder is used. That's why VS can't transform the web.config then because it would change the starting point of the transformation.Sartor
@Nirvan: one more thing: if you also have transformations for debug in a Web.Debug.config file, these will only applied when deploying as well. This might lead to different debug-web.configs.Sartor
Also check out this tool from AppHarbor: webconfigtransformationtester.apphb.comAsyllabic
@Asyllabic thanks for the hint. Looks good and sure is a help when creating a transformationSartor
D
18

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.

Daredeviltry answered 29/4, 2015 at 6:24 Comment(1)
Just a note, the Replace will remove the entire element. When i used this my included assemblies list was removed and I started getting the following error. The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'Links
G
15

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.

Grot answered 16/10, 2014 at 20:52 Comment(0)
S
13

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" />
Synergetic answered 14/9, 2017 at 16:50 Comment(0)
A
2
compilation debug="false" xdt:Transform="SetAttributes"

comes in handy when you are activating XML transformations at release azure deployment time to make configuration transformations specific to a target environment.

When you check XML transform at azure deployment time, the following sequence is done:

  • Apply web.release.config on web.config
  • Apply web.stageName.config on modified web.config.

But web.release.config has already been applied on web.base.config so if

compilation xdt:Transform="RemoveAttributes(debug)" 

is used in web.release.config file, the web.config has already debug attribute been removed at compilation time and when it deploys it transform again with web.release.config, trying to apply the above command but it fails.

Aldarcy answered 14/8, 2019 at 13:16 Comment(0)
A
0

Removing debug attribute is sufficient RemoveAttributes(debug). It will work similar to debug=false.

Alienable answered 7/5, 2018 at 12:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.