0

I had a previously working local configuration that is not bundling even with forcing the settings.

This is happening on both JS and CSS bundling.

Example code only

private static List<string> ScriptBundleExample
{
     get
     {
         return new List<string>()
         {
              "~/Assets/javascriptfile1.js",
              "~/Assets/javascriptfile2.js",
         };
     }
}

// separate function
var bundle = new ScriptBundle("~/Bundles/javascript-example");

ScriptBundleExample.ForEach(script => {
    bundle.Include(script)
}

bundles.Add(bundle);

I have appropriately added the render in my layout:

// different casing to above but never mattered
@Scripts.Render("~/bundles/javascript-example")

I have forced the setting here which should be bundling correctly:

Note: This setting overrides the debug setting within Web.config yet it still doesn't work with both overrides.

BundleTable.EnableOptimizations = true; 

I have also turned off any debugging in Web.config (both in wwwroot and the project file):

<compilation debug="false" targetFramework="4.7.2" />

FWIW minifying also isn't working:

bundle.Transforms.Add(new JsMinify());

Previous related questions on SO


MVC Bundling Not Working

The OP worked on the assumption debug="true" was the correct setting which it was not.


Bundled scripts not working MVC

This was a minification issue which is not the case here.


MVC Bundle not working with Release Configuration (Debug is False), CSS and JS not loading

I'm not getting 404 errors because the bundling isn't working but the proper files are still coming out the server as individual scripts (as if I'm always in debug mode) so the files are being included correctly.


ASP.NET MVC Bundle not rendering script files on staging server. It works on development server

This person just didn't understand the bundling and minification process.

WebGrease package exists in my solution.


Why is my CSS bundling not working with a bin deployed MVC4 app?

Same as above, the OP did not understand how these settings worked. I do not have a .js extension in my bundles.


https://stack247.wordpress.com/2013/02/08/mvc-bundle-not-working-with-release-configuration-debug-is-false/

Not in SO but this didn't work.

  • Please read [ask]. I think the reason why your question has not been answered is that you have failed to provide the full code to replicate the issue. You've not provided the output you're seeing or what you're expecting the output to be. – Mick Mar 08 '21 at 23:43
  • Also read [mcve]. – Mick Mar 08 '21 at 23:44

1 Answers1

0

Everything I did above was correct from a C# point of view. Through running some breakpoints, I realised that the code was bundling correctly but was being overridden by another setting in the pipeline after the one above executed which set BundleTable.EnableOptimizations to false and unbundled everything.

So for anyone reading ahead, if you set the same settings as above, you've done everything right to bundle it from a C# perspective. Check through debugging that the setting is not being overwritten elsewhere.