Recently joining an MVC project (check out, build, run), Visual Studio raised the following error message:
CS0234: The type or namespace name ‘Html’ does not exist in the namespace ‘System.Web.Mvc’ (are you missing an assembly reference?)
The MVC project had System.Web.Mvc, System.Web.Mvc.Html, and other assemblies in its references.
web.config contained all the required namespace declarations
<add namespace="System.Web.Helpers"/> <add namespace="System.Web.Mvc"/> <add namespace="System.Web.Mvc.Ajax"/> <add namespace="System.Web.Mvc.Html"/> <add namespace="System.Web.Routing"/> <add namespace="System.Web.WebPages"/>
but still the error was raised.
Fortunately, the internetz already knew the solution for this problem:
Set the Copy Local flag for each of these assemblies to true.
In hindsight, the solution seems quite logical: if the MVC assemblies are not registered in the GAC, the MVC view compilation triggered by
cannot find the assemblies, which are expected in the GAC or in the /bin directory.
Of course, msbuild could retrieve their location (C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\) from the project file😉