Disable binding / minimization during debugging in WebForms

I want to be able to minimize / merge javascript files in a production environment, while having them unminified / unfundled when debugging locally; however, the default WebForms site in VS2012 does not seem to allow it.

Steps to reproduce my problem:

  • Create a new ASP.NET Web Forms application (C # in my case)
  • Start without debugging and viewing resources in a browser
  • Note the unminified jquery / modernizr files, but bundled with / minified MsAjaxJS and WebFormsJs

web.config by default has:

 <compilation debug="true" targetFramework="4.5"> 

And I even tried to modify Global.asax, explicitly telling BundleTable not to optimize:

 void Application_Start(object sender, EventArgs e) { // Code that runs on application startup BundleTable.EnableOptimizations = false; BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterOpenAuth(); RouteConfig.RegisterRoutes(RouteTable.Routes); } 

However, I still get undebuggable javascript files:

Chrome Dev tools (showing minified / bundled files)

This site (which I understand for MVC) tells me that either debug="true" in web.config or BundleTable.EnableOptimizations = false; in Global.asax should disable functionality. And this site (which is linked to the first for WebForms) does not mention disabling it for debugging.

How can I (purely) tell my project to only minimize / stratify when debug = "false"?

(I am using ASP.NET 4.5)

EDIT:
This question and this question are similar, but both of them only offer a solution using Scripts.Render() . Is there a way to do this using the template method using ScriptManager?

+6
source share
2 answers

Add the following code to the Global.asax.cs file in the Application_Start method. This works great for me.

 #if DEBUG foreach (var bundle in BundleTable.Bundles) { bundle.Transforms.Clear(); } #endif 
+5
source

I had a similar problem. I solved the problem by putting this code

 BundleTable.EnableOptimizations = false; 

after

 BundleConfig.RegisterBundles(BundleTable.Bundles); 
0
source

All Articles