Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove System.Web.Optimization from MVC5

I have a new ASP.NET MVC5 project. I don't want to use Microsoft bundling and minification so I removed the nuget package and the dependencies that I also don't want.

I ensured there was nothing left in the config and I cleared out \Temp\Temporary ASP.NET Files\

I am using VS2013 / IIExpress and there is nothing that references System.Web.Optimization in the aspnet.config or the applicationhost.config

...the solution builds fine but when I run it throws:

Compiler Error Message: CS0234: The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

Something somewhere is trying to pull in the dll, but it's not my code. Seems very odd!

Line 26:     using System.Web.Optimization;

Surely it's not reference by MVC5 itself. Anyone seen this before?


I just found it in the Views folder when I did a search for 'namespaces', no idea how I missed it. I didn't even know there was a config file in the Views folder.

like image 729
Darren Avatar asked Aug 03 '14 08:08

Darren


People also ask

What is System Web optimization?

The System. Web. Optimization namespace includes classes that support Content Delivery Networks (CDN) and the process of optimizing JavaScript and cascading style sheet (CSS) files in a website to reduce file size and improve page performance.

Can I delete Microsoft ASP NET MVC 4 runtime?

You can uninstall Microsoft ASP.NET MVC 4 Runtime from your computer by using the Add/Remove Program feature in the Window's Control Panel.

What is Microsoft Aspnet web optimization?

ASP.NET Optimization introduces a way to bundle and optimize CSS and JavaScript files.

Can I uninstall ASP NET MVC 2?

You can uninstall Microsoft ASP.NET MVC 2 from your computer by using the Add/Remove Program feature in the Window's Control Panel.


2 Answers

I found

<add namespace="System.Web.Optimization" /> 

in the Web.config file under the Views folder. It doesn't get removed with the package.

like image 141
Darren Avatar answered Sep 29 '22 04:09

Darren


In Visual Studio 2012, There was a problem after creating a new Area. In Web.Config of that Area, There was a statement (line) that Visual Studio Compiler wants to use Microsoft.AspNet.Web.Optimization! And when you run the application and you want to see some of views in that Area, You get an error because of that statement (line).

Solution (1)

Delete that statement (line) Microsoft.AspNet.Web.Optimization in Web.Config of Areas (in Visual Studio 2012)

Solution (2)

You can install the Web.Optimization for your application with NUGET:

INSTALL-PACKAGE Microsoft.AspNet.Web.Optimization

like image 41
Dariush Tasdighi Avatar answered Sep 29 '22 03:09

Dariush Tasdighi