.net-4.0 - 为什么在新的 MVC4 项目中会出现编译错误?

标签 .net-4.0 asp.net-mvc-4 visual-studio-2012

我一直无法找到答案,整个周末都在网上搜索,所以我希望你能帮我解决这个问题。

使用 Visual Studio 2012 时,我创建了一个新的 MVC4 Web 应用程序项目并遇到一些编译错误。

这是我的问题:

  • 我使用 Visual Studio 2012 创建了一个新的 MVC4 Web 应用程序,我选择了 Internet 应用程序并将其设置为使用 RAZOR 引擎。
  • 我转到应用程序属性并在应用程序选项卡下将目标框架从 .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, 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 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

  • 最佳答案

    只需重新安装 EntityFramework:

  • 转到包管理器控制台
  • 卸载包 entityframework
  • 安装包 Entity Framework

  • 这就是错误应该消失!

    关于.net-4.0 - 为什么在新的 MVC4 项目中会出现编译错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12665217/

    相关文章:

    wpf - WPF ItemsControl中的项目间距

    c# - 在 .NET 4.0 的 ConcurrentDictionary 中使用 AddOrUpdate 方法

    c# - Visual Studio 2012 中嵌入式语言的语法突出显示

    c# - 单元测试时我怎么能 "uninitialize"WebSecurity?

    visual-studio - 交替使用 msbuild 和 devenv 构建相同的解决方案

    C# 多个组合框并显示它们的值

    c# - WPF 应用程序自定义 TTF 字体未使用?

    asp.net - 在 IIS 6 上使用路由部署 ASP.NET 4 Web 表单应用程序

    c# - asp.net MVC 4 - 复选框项目的输出列表,将选择与用户相关联 - 允许稍后显示和编辑

    asp.net-mvc-4 - ClaimsAuthorizationManager.CheckAccess : Handling false without going to login page