7
votes

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.

2
What's the exact error you're seeing?haim770
Possibly in Web.Config file <system.web><pages><namespaces> sectionuser3559349
Can you post the full stacktrace as well?haim770
@stephen-muecke I have checked that several times. It's a pretty minimal config file.Darren
Did you check both files (the one in the Views folder as well)?user3559349

2 Answers

21
votes

I found

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

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

3
votes

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