ASP.NET MVC4 Bundling and Minification: Where did System.Web.Optimization go?

Recently we upgraded an MVC 3 application to MVC4 and wanted to take advantage of the new bundling and minification functionality for our css and js files.   There are some great articles on the asp.net site about how to use all of these new features:

http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification

Initially I tested it out on a brand new MVC 4 project I created in VS2012.  It worked exactly as advertised, so I was anxious to get it working in one of our actual production web applications.  However, my first attempts at adding bundling to our application left me a little frustrated. 

When I tried to add the example code for using  BundleConfig and BundleTable to my Global.asax, these classes could not be found.  That seemed a little strange since this was a working MVC4 application.  Why were the references available in the brand new application I had created (based on the MVC4 application template) and not in my upgraded MVC4 application?

After doing a little research I realized that the MVC4 template in VS had references to Nuget packages which included this functionality.  So the new optimization framework was not part of the MVC bits, but rather an add-on package.  This actually made a lot of sense because it allows it to easily be shared with other types of ASP.NET projects and to be deployed in isolation.  I just wasn’t expecting this initially, so it took me a little time to figure out where to get the bits I needed to add this functionality to our application.

To add bundling and minification to an existing MVC application you need to add the following Nuget packages:

I would recommend grabbing the latest versions of these packages.  Once you’ve done that then the rest should work as advertised.  Enjoy!

2 thoughts on “ASP.NET MVC4 Bundling and Minification: Where did System.Web.Optimization go?

  1. Hi!

    Bundling and minification are two techniques you can use in ASP.NET 4.5 to improve request load time. Bundling and minification improves load time by reducing the number of requests to the server and reducing the size of requested assets (such as CSS and JavaScript.)
    So thanks for sharing this important information through this article. There are few other links that have described for manage “Bundling and minification”.

    http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification

    http://www.mindstick.com/Articles/2d3da74a-94da-45fe-b361-97263cd725f2/?Bundling%20and%20Minification%20in%20ASP%20NET%20MVC%204

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.