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.*"));

8
  • "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) Commented May 30, 2013 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. Commented May 30, 2013 at 17:08
  • Check for any changes to web.config, which can override some defaults. Commented May 30, 2013 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. Commented May 30, 2013 at 18:13
  • 1
    Not really Liam. Just like everyone else you have misread this question. Commented Feb 10, 2015 at 14:43

4 Answers 4

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;
}
Sign up to request clarification or add additional context in comments.

4 Comments

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.
Oh I see, misread that. Try setting that to false the explicitly.
The BundleTable.EnableOptimizations value is already false whenever I check it in the immediate window or in the watch window.
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 go.microsoft.com/fwlink/?LinkId=301862 BundleTable.EnableOptimizations = true;`
3

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

<configuration>
    <system.web>
        <compilation debug="false" targetFramework="4.0" />

1 Comment

Thanks for the reply @brettof86. Debug in my app is set to true.
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.

4 Comments

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.
@1576573987 - maybe you could quickly specify why this answer was helpful to you? That would be much appreciated. Thanks a lot !!!
@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.
this is simply a series of guesses
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.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.