当使用Visual Studio 2012时,我创建一个新的MVC4 Web应用程序项目并获得一些编译错误.
这是我的问题:
>我使用Visual Studio 2012创建一个新的MVC4 Web应用程序,我选择Internet应用程序并将其设置为使用RAZOR Engine.
>我去应用程序属性,在应用程序选项卡下,将目标框架从.NET Framework 4.5更改为.NET Framework 4.
>构建会产生以下错误:
Error 1 The type name ‘TableAttribute’ could not be found. This type has been forwarded to assembly ‘System.ComponentModel.DataAnnotations,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35’. Consider adding a reference to that assembly. c:\users\saad\documents\visual studio 2012\Projects\MvcApplication1\MvcApplication1\Models\AccountModels.cs 21 6 MvcApplication1
Error 2 The type or namespace name ‘Table’ could not be found (are you missing a using directive or an assembly reference?) c:\users\saad\documents\visual studio 2012\Projects\MvcApplication1\MvcApplication1\Models\AccountModels.cs 21 6 MvcApplication1
Error 3 The type or namespace name ‘DatabaseGeneratedAttributeAttribute’ could not be found (are you missing a using directive or an assembly reference?) c:\users\saad\documents\visual studio 2012\Projects\MvcApplication1\MvcApplication1\Models\AccountModels.cs 25 10 MvcApplication1
Error 4 The type name ‘DatabaseGeneratedAttribute’ could not be found. This type has been forwarded to assembly ‘System.ComponentModel.DataAnnotations,PublicKeyToken=31bf3856ad364e35’. Consider adding a reference to that assembly. c:\users\saad\documents\visual studio 2012\Projects\MvcApplication1\MvcApplication1\Models\AccountModels.cs 25 10 MvcApplication1
Error 5 The type or namespace name ‘CompareAttribute’ could not be found (are you missing a using directive or an assembly reference?) c:\users\saad\documents\visual studio 2012\Projects\MvcApplication1\MvcApplication1\Models\AccountModels.cs 54 10 MvcApplication1
Error 6 The type or namespace name ‘Compare’ could not be found (are you missing a using directive or an assembly reference?) c:\users\saad\documents\visual studio 2012\Projects\MvcApplication1\MvcApplication1\Models\AccountModels.cs 54 10 MvcApplication1
Error 7 The type or namespace name ‘CompareAttribute’ could not be found (are you missing a using directive or an assembly reference?) c:\users\saad\documents\visual studio 2012\Projects\MvcApplication1\MvcApplication1\Models\AccountModels.cs 87 10 MvcApplication1
Error 8 The type or namespace name ‘Compare’ could not be found (are you missing a using directive or an assembly reference?) c:\users\saad\documents\visual studio 2012\Projects\MvcApplication1\MvcApplication1\Models\AccountModels.cs 87 10 MvcApplication1
解决方法
>转到包管理器控制台
>卸载 – 包实体框架
>安装包实体框架
那就是错误应该消失!