Asp.net-mvc – System.Web.Optimization and Microsoft.Web.Optimization won’t load reference in vs 2012

asp.net-mvcasp.net-optimization

I'm working on an MVC 4 project started in Visual Studio 2010. Right now I'm working on a machine with Visual Studio 2012 as I don't have access to the machine I was originally working on. I tried all morning to find answers, but they don't seem to help my situation.

I followed How to add reference to System.Web.Optimization for MVC-3-converted-to-4 app and installed from nuget right into my solution. Even though I have all the required reference packages downloaded and installed on my machine, System.Web.Optimization continues to remain missing. Is there anything else I can do?

Edit: When I try to build the project I receive the following errors

  • The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) – BundleConfig.cs
  • The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) – Global.asax.cs
  • The type or namespace 'BundleCollection' could not be found (are you missing a using directive or an assembly reference?) – BundleConfig.cs

My BundleConfig.cs contains

using System.Web;
using System.Web.Optimization;

namespace BCCDC_AdminTool
{
    public class BundleConfig
    {
     // For more information on Bundling, visit http://go.microsoft.com/fwlink/?    LinkId=254725
    public static void RegisterBundles(BundleCollection bundles)
    {
           bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

           bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                    "~/Scripts/jquery-ui-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.unobtrusive*",
                    "~/Scripts/jquery.validate*"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

            bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));

            bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
                    "~/Content/themes/base/jquery.ui.core.css",
                    "~/Content/themes/base/jquery.ui.resizable.css",
                    "~/Content/themes/base/jquery.ui.selectable.css",
                    "~/Content/themes/base/jquery.ui.accordion.css",
                    "~/Content/themes/base/jquery.ui.autocomplete.css",
                    "~/Content/themes/base/jquery.ui.button.css",
                    "~/Content/themes/base/jquery.ui.dialog.css",
                    "~/Content/themes/base/jquery.ui.slider.css",
                    "~/Content/themes/base/jquery.ui.tabs.css",
                    "~/Content/themes/base/jquery.ui.datepicker.css",
                    "~/Content/themes/base/jquery.ui.progressbar.css",
                    "~/Content/themes/base/jquery.ui.theme.css"));
        }
    }
}

Best Answer

I had the same problem with a VS2010 project I opened in VS2012. The Microsoft.AspNet.Web.Optimization package was missing so I just needed to download it using Nuget Package Manager.

You can run in the console: Install-Package Microsoft.AspNet.Web.Optimization

Related Topic