Using bundles in WebForms outputs the minified/combined file even in debug mode
Asked Answered
Q

1

6

I've created a bundle of various script files that I want to be combined/minified together. In my code behind file (yes, sorry it's in VB!) I add it to a <asp:placeholder /> on the <head> like this

Me.PlhHeader.Controls.Add(New LiteralControl(Scripts.Render("~/bundles/main").ToHtmlString()))

This will work, but it always seems to output the compressed minified version, even when debug="true" in the Web.Config.

no matter what, this is what is output: <script src="/bundles/main"></script>

What do I need to do differently to make this output the individual uncompressed files when in debug mode?


EDIT

I've also tried to manually set the option BundleTable.EnableOptimizations = false and it still outputs the single minified script tag. I'm out of ideas.


Final Edit

I was doing something very dumb with some related code, but technically everything with the bundles was fine and working correctly. Problem solved for me!

Quarterstaff answered 17/4, 2013 at 20:48 Comment(4)
Possible dup: #11945245Benedick
No, that shouldn't be a duplicate (of that question anyway). I just updated with a few more clarifications.Quarterstaff
What version of .NET? 4?Tarton
We are using the latest, .NET 4.5Quarterstaff
G
1

I would recommend you to install the Microsoft.AspNet.WebOptimization.WebForms. It works really well.

Microsoft.AspNet.WebOptimization.WebForms

Then you can use:

<%: System.Web.Optimization.Scripts.Render("~/bundles/main") %>
Geber answered 7/5, 2013 at 1:44 Comment(3)
I already have this installed, which is how I'm able to create working bundles. The problem I'm having is that I can never get it to use the unbundled files when in debug mode.Quarterstaff
I get it ;) It should't bundle on Debug mode. Best thing to do is check the Publish Profiles on the project. I have experienced something similar when I didn't have the Script/Css files on the publish settings. Check this "not so up to date" solution I have done before the nuget package. It might point you in the right direction. linkGeber
Also remove any obj/[debug][release]/packages/PackageTmp folder. MSBuild compiles your WebApplication on this folder before it publishes to the destination folder.Geber

© 2022 - 2024 — McMap. All rights reserved.