Resolved: I’m trying to understand how/if Bundling and Nuget packages work together


I’m an old COBOL programmer that has self-taught myself web development over the last decade. I’ve always used for developing and when I first started out I had no clue what I was doing. There are some cases I still don’t :). That brings me to my question. When I first started out I didn’t know what Nuget packages were so if I wanted to use something like bootstrap I would would download the files from the bootstrap website and load them into my project in a Scripts folder. To call the files I added them into the bundling function provided by I’ve since discovered Nuget Manager and keep my bootstrap versions updated through it, but I’ve always been afraid to remove the reference to these files from the bundling package.
Today I’m trying to upgrade bootstrap from 4.6 to 5.1, but I’m getting an error. If I go into my bundling package and comment out the reference to bootstrap my error goes away. So my question is, if I’m using Nuget to manage my packages, is it safe to remove them from the bundling package? I feel like the answer is “yes it’s safe” but was hoping for confirmation and maybe an explanation on how and if Nuget and bundling work together, if at all…


Well, nuget simple in “most” cases downloads some .net .dll’s and assemblies, and then often sets a reference for you. (you could do this manual, but hey its a whole lot less work).
but, when you use nuget to install those packages, some might include javaScript libries and code (such as your example).
Because the bundling expects the scripts to be say in this location:
 Public Shared Sub RegisterBundles(ByVal bundles As BundleCollection)
    bundles.Add(New ScriptBundle("~/bundles/WebFormsJs").Include(
 etc. etc. etc.c
Then of course, when you nuget a package, then the location of the scripts VERY LIKLEY is not going to be the above location.
So, you would then remove your older scripts (and above script referances), and add in the new location of such scripts.
So, you are free to remove the existing bundling references, but you not then enjoy use of the script manager and system to “merge together” the many script files.
So, you don’t have to use bundeling anyway.
However, in most cases, you WANT BOTH the SomeJava.js and SomeJava.min.js files to exist. And if you modify those files, then YOU need to regenerate the .min version. Since you not (likely) to be modifying those .js files, then you can well dump the bundling of such files. But you are free also to add them to the above bundling reference.
All bundling does is “merge” the .js files together – so that you don’t have 50 or 100 different separate .js files, and thus 50 or 100 difference downloads and references in a web page to use all those many .js files.
So, it not a huge deal. If you only adding say bootstrap via nuget, then I would hunt down the location of the new .js files, and add them to the bundling. But, it not all that huge of a deal if you don’t. The issue then becomes how do you add the new .js and .css files to the given web page you are working on. (and toss in use of a master page, and again more complex).
So, in theory, you could remove the existing (older .js references) and then add the css. files that nuget created. I not looked, and don’t know if the .js files remain in “packages” folder, or during an install that nuget copies to some folder (such as scirpts).
Just keep in mind, do keep and have the .min versions of those .js files. if you in web.config set debug=false, then the web site flips over to using the .min versions of the .js files – they have to exist, and even without bundling they have to exist, and this “flip” occurs (you now using .min versions of js files).
This is a HUGE topic, and probably oh so far beyond that of a simple post on SO.
but, suffice to say, you can well dump use of the bundling, and remove your older .js references. (but, since you having to do that, then might as well add the newer references then at that point in time, right???).

If you have better answer, please add a comment about this, thank you!

If you like this answer, you can give me a coffee by <a href=””>click here</a>