How to remove System.Web.Optimization from MVC5 - asp.net-mvc

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.

I found
<add namespace="System.Web.Optimization" />
in the Web.config file under the Views folder. It doesn't get removed with the package.

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

Related

Visual Studio 2015 - MVC 4 - Razor compile errors

Since updating to Visual Studio 2015 Update 1, my MVC 4 project has compile errors in several view files. The errors are related to the following:
For loops (you must declare a type for the temporary variable or it is not recognized)
Linq expressions are not recongized (For example: Orderby is not a member of List(Of String))
Html.DisplayFor is not recognized (Reference required to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' containing the type 'Expression(Of )'. Add one to your project.)
Other than these 3 type of errors, the intellisense in vbhtml files seems fine. And in VS2013 none of the above was an issue so these errors did not exist before updating.
According to this post, it sounds like my version of Visual Studio should have this resolved. I have tried adding a reference to System.Core but I get an error that it has already added. I also tried deleting the 14.0 folder from the AppData folder but that didn't help. Any suggestions?
I had the same issue in Visual Studio 2017. I was able to fix it by updating the version numbers for System.Web.Mvc in the <pages> section of Views\web.config to match the version referenced by the project. Thanks to JamieD77's comment for pointing in the right direction.

Problems after migrating VS2013 to VS2015 in MVC

UPDATED QUESTION
I have a project that I've started in VS 2013 and was setup as the following:
MyMainMvcApp (Containing core Functionality)
MyPlugin (Containing plugable customer stuff)
MyPlugin contains some *.cshtml views as embedded resource and some controllers.
In VS2013 I was able open the Views and i had full Razor Intellisense and no issues when compiling.
IN V2015 the Error List is showing a lot of errors like
Feature 'lambda expression' is not available in C# 2. Please use language version 3 or greater.
The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
etc etc
Of course I have all the Assemblies referenced. And the projects even compile.
I believe that VS 2015 is just missing some config stuff in web.config or similar, so that he can resolve the stuff while having the view open in designer.
I have an app.config in MyPlugin project that has been added from Nuget.
I've put the same config stuff as my web.config in there but that didn't help.
As well I copied the MyMainMvcApp\Views\web.config into MyPlugin\Views\web.config that didn't work as well.
Any idea what the issue might be or ideas how to solve it?
I've started MyPlugin as a Class Library in VS 2013 and that worked well. Afterwards I was not able to make MyPlugin work as desired in VS 2015 designer. I've created a new MyPlugin Project as a MVC Project and copied all my code from the old library to the new.
It's a workaround but that solves my VS 2015 problems.
The fact that it's trying to utilize C# 2, is pretty concerning. Make sure your project is targeting the latest version of .NET you feel comfortable with. Since you're using VS2015, go all the way to 4.6 if you like, or if you want something a little more hardened, stick with 4.5.2. Just right-click your project in the Solution Explorer and choose "Properties". Then on the first "Application" tab, change the "Target framework" drop-down to something appropriate.

Taghelper: Cannot resolve TagHelper containing assembly

I cannot get a custom TagHelper to work in my ASP.NET v5 project. The custom TagHelper is located in the web project itself. I tried following this sample this sample from CodeProject and this tutorial too.
When I try to use the tag without addTagHelper:
nothing is transformed, no breakpoints hit in the tag helper.
When I try to #addTagHelper "*, MyWebApplication" to the Viewcomponent, the error is MyWebApplication'. Error: Could not load file or assembly 'MyWebApplication'.
What am I missing?
Tool versions:
Microsoft Visual Studio Enterprise 2015 RC
Version 14.0.22823.1 D14REL
Microsoft .NET Framework Version 4.6.00057
Microsoft.AspNet.Mvc 6.0.0-beta4
The advertised signature for addTagHelper is
#addTagHelper "className/Filter", "assemblyName"
Behaviour actually appears to be (at least for helpers in same web project)
addTagHelper "className/Filter", "folderName"
because at least into Beta6, the assembly name is the folder name and ignores the attributes in the project properties.
Here is a sample working demo
Hit F5, view cats.
Edit the project properties to change the assembly name.
Hit F5, view cats. << This should not work?!
Close solution, rename the on disk directory TagHelperDemo ->
TagHelperFolderDemo
Observe page fails until the folder name is used for addTagHelper directive
PS: #addTagHelper is required even when the TagHelper is in the same project. VS2015 re-colours the tag as purple when it is targeted by a TagHelper.

MVC3 .Net precompile issue in IIS 6

I have an MVC3 C# .Net web app and I am running aspnet_compiler on my app in order to precompile. I am running this command:
aspnet_compiler -v /dev/boe
Boe is the app in the dev structure under "Default Web Site". The above command is producing this error.
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\dev_boe\25d5f53a\2ad742fc\App_Web_vujir5mm.0.cs(29): error CS0234: The type or namespace name 'Models' does not exist in the namespace 'BOE' (are you missing an assembly reference?)
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\dev_boe\25d5f53a\2ad742fc\App_Web_vujir5mm.2.cs(29): error CS0234: The type or namespace name 'Models' does not exist in the namespace 'BOE' (are you missing an assembly reference?)
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\dev_boe\25d5f53a\2ad742fc\App_Web_vujir5mm.3.cs(29): error CS0234: The type or namespace name 'Models' does not exist in the namespace 'BOE' (are you missing an assembly reference?)
However, Models isn't in our solution. We have our Model objects in a Domain project that is referenced by our web app. It appears that the compiler is expecting a Models reference in our MVC app. Is this true? Or is something else causing this error?
Thanks to David Hirst's suggestion to look at the line of code in the temp file I found the issue:
Basically, there were files that were not included in the Visual Studio solution BUT were still in the file structure on my machine. There were 3 .cshtml files referencing Models. Since the files were not included in the solution, they were not included in a Build using VS. And also, since they were not in the solution, when I did a search for Models, I didn't get any results...but the compiler sweeps the entire directory structure and therefore tried to compile the files with the bad references.
Outstanding lesson in being sure to remove legacy code, and make sure the code base and file structures are in snyc.
I have had a similar error when trying to use the Razor engine on IIS 7.5 (even though .NET 4 was installed!)
If you have a reference in your project as you suggest you may need to go into references, highlight it, go properties and under Copy Local, set this to true. Re-Publish and hopefully this will solve your problem as it did mine.

Razor MVC application failed to load FreeTextBox but it doesn't have a FreeTextBox

I uploaded my MVC3 Razor application to the webhost provider (works fine on my development server under Visual Studio 2010).
On the deployed site I get a
"Could not load file or assembly 'FreeTextBox, Version=3.3.1.12354, Culture=neutral, PublicKeyToken=5962a4e684a48b87' or one of its dependencies. The system cannot find the file specified."
But I am totally puzzled, my application does NOT have ANY FreeTextBox in it! I am not even referencing that DLL. Unfortunately the "Detaile" IIS error doesn't even mention who or what is trying to load that DLL so I have no idea where it is coming from.
To triple check I did a search on FreeTextBox on my self-built app with search mask . on the ENTIRE solution and Visual Studio can't find anything.
Here the Actual Solution
It was indeed inheriting an assembly of the parent application.
Ketan as per your suggestion I solved it by doing this:
<system.web>
<assemblies>
<clear/>
... here standard MVC3 assemblies of template project ...
</assemblies>**
</system.web>
Is your app folder on shared host configured as an "Application"? If not then it probably is using the machine.config or web.config at a higher level where there is a reference of that control. The FreeTextBox is a ASP.NET WYSWYG Text editor something that webhosts normally include in their hosting packages as free. I would contact their tech support to fix this.
you are referencing a assembly with a dependency on "FreeTextBox".
deploy the .dll containing the "FreeTextBox" assembly to your /bin dir or find the offending assembly with a tool like
.NET Reflector
NDepend
dotPeek

Resources