8

"The issue is that, by default, asp.net mvc DOES NOT bundle the css and js files in debug mode. But our css and js files ARE getting bundled in the debug mode."

For some reason, all the css and js files are being bundled in debug mode. It started few days ago. We have a large team with several developers and its hard to find out what changed in the last few days because there are several changes submitted to the repository. However I didn't find any significant changes in the BundleConfig and Global.asax.cs.

When the application is running in debug mode, BundleTable.EnableOptimizations returns a false.

To my understanding when debug is set to true then bundling does not happen. <compilation debug="true" targetFramework="4.5">

So far I haven't found a single occurrence of this issue on Google. Is this a very unique problem?

Ideally instead of a workaround I would like to fix it. Finding the cause is the actual problem here. Any pointers on where I should start looking for the fix would be appreciated. Thank you.

Edit: My question is similar to but not exactly the same as ASP.NET MVC 4 app with bundling and minification, why is minification enabled in debug mode? Someone please remove the "This question may already have an answer here:" tag. In my case the bundle paths are already starting with a "~"

Template: @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/js")

Bundle Config: bundles.Add(new Bundle("~/Content/css").Include("~/Content/*.css")); bundles.Add(new Bundle("~/bundles/js").Include("~/Scripts/myproj.*"));

Community
  • 1
  • 1
Oxon
  • 4,901
  • 8
  • 40
  • 54
  • "When the application is running in debug mode, BundleTable.EnableOptimizations returns a false" ... is this what you meant to write, because that is the expected behavior (bundling turned off in DEBUG) – Faust May 30 '13 at 15:23
  • In debug mode BundleTable.EnableOptimizations returns false. We are also getting false from BundleTable.EnableOptimizations when in debug. The issue is that, by default, asp.net mvc does not bundle the css and js files in debug. But our css and js files are getting bundled. – Oxon May 30 '13 at 17:08
  • Check for any changes to web.config, which can override some defaults. – Robert McKee May 30 '13 at 17:17
  • I didn't find any changes in the web.config, global.asax and the bundle config. That's what surprises me the most. – Oxon May 30 '13 at 18:13
  • possible duplicate of [ASP.NET MVC 4 app with bundling and minification, why is minification enabled in debug mode?](http://stackoverflow.com/questions/11952491/asp-net-mvc-4-app-with-bundling-and-minification-why-is-minification-enabled-in) – Michael Jul 27 '13 at 22:17
  • possible duplicate of [Enable bundling and minification in debug mode in ASP.NET MVC 4](http://stackoverflow.com/questions/16030905/enable-bundling-and-minification-in-debug-mode-in-asp-net-mvc-4) – Liam Feb 10 '15 at 10:18
  • 1
    Not really Liam. Just like everyone else you have misread this question. – Oxon Feb 10 '15 at 14:43
  • I'm having the exact same problem, Have you been able to find any solution so far? – slashCoder May 12 '16 at 21:21

4 Answers4

9

Try adding this in your global Application_Start()

BundleTable.EnableOptimizations = false;

So...

protected void Application_Start()
{
     AreaRegistration.RegisterAllAreas();
     WebApiConfig.Register(GlobalConfiguration.Configuration);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     AuthConfig.RegisterAuth();

     BundleTable.EnableOptimizations = false;
}
Gabe
  • 49,577
  • 28
  • 142
  • 181
  • The solution you have written is for bundling the css and js files in debug mode. I think I did not make it clear enough hence the confusion. In our case our files are getting bundled in debug mode and we do not want this to happen. We havent set `BundleTable.EnableOptimizations = true;` anywhere in the system. – Oxon May 30 '13 at 17:13
  • Oh I see, misread that. Try setting that to false the explicitly. – Gabe May 30 '13 at 17:37
  • 2
    The BundleTable.EnableOptimizations value is already false whenever I check it in the immediate window or in the watch window. – Oxon May 30 '13 at 18:12
  • Thanks, I am using the asp.net template for Single Page application and I had to set it to comment it, it was true by default. // Set EnableOptimizations to false for debugging. For more information, ` // visit http://go.microsoft.com/fwlink/?LinkId=301862 BundleTable.EnableOptimizations = true;` – Ronen Festinger Dec 29 '14 at 22:38
3

For me the issue was in the web.config "debug" was set to false.

<configuration>
    <system.web>
        <compilation debug="false" targetFramework="4.0" />
Liam
  • 27,717
  • 28
  • 128
  • 190
blockloop
  • 5,565
  • 5
  • 30
  • 31
2

Try troubleshooting outside of MVC specifically.

Does this problem now transcend your entire team or just your machine? If it's the entire team at least you know the change happened somewhere in the commit cycle.

Have you rebuilt the solution? Cleaned properly? Are you running IIS, IIS Express, or Cassini? Are you absolutely certain that the site/build you're running in the debugger is not in release mode? You may be debugging a specific build that isn't being modified through the build pipeline (failed builds definitely fall under this category).

I'm using VS 2010 and MVC 4 and by default in debug mode, I see absolutely no bundling. I don't have to explicitly set anything. If you're seeing differently, something obviously has to account for it as this isn't normal behavior.

I have a feeling your best approach is the hardest: unwind your commits. Make a copy of your working directory and revert to sometime before this happened. Verify the problem does not occur in this build, don't just assume. Now checkout a commit half way between that point in time and now. Test again. If the build is still good, cut the time in half and repeat. Once you've hit the issue, you know the commit it was introduced in is somewhere between your last "good" commit and the one you're currently testing. This technique greatly simplifies isolating a problem to a specific commit. I almost never go one commit at a time unless I'm completely unsure of the code or I already have a good indication of where it might be.

w0rd-driven
  • 933
  • 7
  • 13
  • Unfortunately this answer didn't really help me. I have come across the same issue - usiung VS 2013 Express for Web and MVC 5. I've only got my one machine and I can't go back to a previous working version because I have only used bundling for the first time today - with the very same behaviour as described in the question. – ralfonso Aug 18 '14 at 11:36
  • @1576573987 - maybe you could quickly specify why this answer was helpful to you? That would be much appreciated. Thanks a lot !!! – ralfonso Aug 18 '14 at 11:38
  • @1576573987 - in fact I just created a brand new project (out of the box with the MVC 5 template) and noticed the same behaviour there as well. So I never even touched web.config, Global.asax or any other file. So it looks more like a setting on the development PC that forces the bundling to switch to minifying even though the project is in debug mode. – ralfonso Aug 18 '14 at 11:53
  • this is simply a series of guesses – Liam Feb 10 '15 at 10:11
1

In my case I had used

@Scripts.Render("/Bundles/scriptname")

When I replaced it with

@Scripts.Render("~/Bundles/scriptname")

it worked. The '~' made all the difference.

David Hyde
  • 902
  • 9
  • 18
  • in my case it was the version number. I have changed it from `@Scripts.Render(string.Format("~/bundles/js/script?v={0}", versionNumber))` to `@Scripts.Render("~/bundles/js/script")`. Just in case it helps someone. – Naveed Quadri Jul 19 '18 at 07:28