生成视图时出现 Entity Framework Power Tools 错误

EntityFramwork Power Tools error while generating views

当尝试使用 EntityFramework Power Tools (0.9 beta) 的 Generate Views 功能时,生成失败并且我在输出 window 处收到以下错误:

System.Reflection.TargetInvocationException: 
Exception has been thrown by    the target of an invocation. --->
System.TypeLoadException: Could not load type 
'System.ComponentModel.DataAnnotations.Schema.IndexAttribute' from assembly 
'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at MyProject.Entities.Models.MyDbContext.OnModelCreating(DbModelBuilder modelBuilder)

我的上下文继承自 IdentityDbContext,当强大的工具试图为身份模型生成视图时,似乎是什么导致了这个问题。

只有在尝试生成视图时才会发生这种情况。解决方案本身构建和运行没有任何错误。

为了简化和隔离这个问题,我在 vs 2013 中创建了一个新的网站项目,具有身份和 entity framework 6.0,生成工作正常。将包更新到 Identity 2.2.1 和 EntityFramework 6.1.3 导致错误并且生成失败。

我检查了项目参考,似乎参考了正确的 Entityframework 版本。

我的 .csproj 引用:

<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer">
  <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.Core">
  <HintPath>..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.EntityFramework">
  <HintPath>..\packages\Microsoft.AspNet.Identity.EntityFramework.2.2.1\lib\net45\Microsoft.AspNet.Identity.EntityFramework.dll</HintPath>
</Reference>

貌似Power tools坚持要用6.0版本,还没有System.ComponentModel.DataAnnotations.Schema.IndexAttribute类型,因为6.1版本才引入,但是加入到最新的Identity模型中限制了唯一的用户名。

有什么想法吗?

事实证明,Power 工具使用的是 EntityFramework 的 Visual Studio IDE 版本,而不是项目中引用的版本。在我的例子中是 6.0.2。在我的机器上安装 Visual Studio 2013 Update 5 (2013.5) RTM 解决了问题,现在使用最新的 EntityFramework 6.1.3。