I have debug="true"
in both my web.config(s), and I just don't want my bundles minified, but nothing I do seems to disable it. I've tried enableoptimisations=false
, here is my code:
//Javascript
bundles.Add(new ScriptBundle("~/bundles/MainJS")
.Include("~/Scripts/regular/lib/mvc/jquery.validate.unobtrusive.js*")
.Include("~/Scripts/regular/lib/mvc/jquery.validate*")
.Include("~/Scripts/regular/lib/bootstrap.js")
.IncludeDirectory("~/Scripts/regular/modules", "*.js", true)
.IncludeDirectory("~/Scripts/regular/pages", "*.js", true)
.IncludeDirectory("~/Scripts/regular/misc", "*.js", true));
//CSS
bundles.Add(new StyleBundle("~/bundles/MainCSS")
.Include("~/Content/css/regular/lib/bootstrap.css*")
.IncludeDirectory("~/Content/css/regular/modules", "*.css", true)
.IncludeDirectory("~/Content/css/regular/pages", "*.css", true))
If you set the following property to false then it will disable both bundling and minification.
In Global.asax.cs
I combined a few answers given by others in this question to come up with another alternative solution.
Goal: To always bundle the files, to disable the JS and CSS minification in the event that
<compilation debug="true" ... />
and to always apply a custom transformation to the CSS bundle.My solution:
1) In web.config:
<compilation debug="true" ... />
2) In the Global.asax Application_Start() method:
Just to supplement the answers already given, if you also want to NOT minify/obfuscate/concatenate SOME files while still allowing full bundling and minification for other files the best option is to go with a custom renderer which will read the contents of a particular bundle(s) and render the files in the page rather than render the bundle's virtual path. I personally required this because IE 9 was $*%@ing the bed when my CSS files were being bundled even with minification turned off.
Thanks very much to this article, which gave me the starting point for the code which I used to create a CSS Renderer which would render the files for the CSS but still allow the system to render my javascript files bundled/minified/obfuscated.
Created the static helper class:
Then in the razor layout file:
instead of the standard:
I am sure creating an optional renderer for javascript files would need little to update to this helper as well.
Here's how to disable minification on a per-bundle basis:
Sidenote: The paths used for your bundles must not coincide with any actual path in your published builds otherwise nothing will work. Also make sure to avoid using .js, .css and/or '.' and '_' anywhere in the name of the bundle. Keep the name as simple and as straightforward as possible, like in the example above.
The helper classes are shown below. Notice that in order to make these classes future-proof we surgically remove the js/css minifying instances instead of using .clear() and we also insert a mime-type-setter transformation without which production builds are bound to run into trouble especially when it comes to properly handing over css-bundles (firefox and chrome reject css bundles with mime-type set to "text/html" which is the default):
To make this whole thing work you need to install (via nuget):
WebGrease 1.6.0+ Microsoft.AspNet.Web.Optimization 1.1.3+
And your web.config should be enriched like so:
Note that you might have to take extra steps to make your css-bundles work in terms of fonts etc. But that's a different story.
To disable bundling and minification just put this your .aspx file (this will disable optimization even if
debug=true
in web.config)vb.net:
c#.net
If you put
EnableOptimizations = true
this will bundle and minify even ifdebug=true
in web.configCombine several answers, this works for me in ASP.NET MVC 4.