Search code examples
cssasp.net-mvc-4bundlewebgrease

WebGrease error on Styles.Render call in _Layout.cshtml in Mvc4


I'm trying to add bundling to my Mvc4 web project. The steps I took:

  1. Added a reference to my project to System.Web.Optimization
  2. Added @Styles.Render("~/Content/css") within <head> of my _Layout.cshtml
  3. Added BundleConfig.RegisterBundles(BundleTable.Bundles); to Global.asax.cs
  4. Added BundleConfig.cs to my App_Start folder with bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css")); within RegisterBundles(...) method
  5. Added a simple site.css within my Content folder.

The error that I get on the line from step #2 above is Could not load file or assembly 'WebGrease, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

enter image description here

Am I missing a DLL reference or something? Note that I started originally from a blank Mvc4 project.


Solution

  • Over the last day or so I was having this issue too but I figured out a solution. Basically you need to just update "webgrease".

    Here's what I did to update webgrease:

    1. right click your project solution in your solution explorer.
    2. Click "Manage NuGet Packages for Solution"
    3. Go to the updates section on the left
    4. Search "WebGrease"
    5. Then update "WebGrease"

    This worked for me when I built my solution.