无法使用数据注释

所以在这里我们试图在游戏开始之前处理EF7并且我遇到了我只能称之为疯狂的事情。

在EF6中我使用了相当多的注释,我试图将其转移到EF7中,根据UnicornStore项目,这是完全有效的,但是我遇到了一个问题,其中visual studio 2015抱怨我没有参考到System.ComponentModel.DataAnnotations程序集。 很公平,我添加了对程序集的引用,现在我从DNX Core 5.0获得以下内容:

Error CS0234 The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) Lib.DNX Core 5.0 

对于我的生活,我无法弄清楚这里发生了什么,因为当我看到UnicornStore作为我的参考时,在project.json中没有对该程序集的引用,但是项目中有一个引用。 lock.json,据我所知,你不应该编辑那个文件。

最重要的问题是我做错了什么? 为什么DNX 4.5.x不会抱怨引用而DNX Core 5.0呢?

.Net 4.6(也称为vNext)Web项目依赖于Microsoft.AspNet.Mvc 。 这引入了一个很大的依赖树,数据注释在Microsoft.DataAnnotations包下

在项目中使用Data注释使用Microsoft.DataAnnotations代替System.ComponantModel.DataAnnotations

我恰好在beta8中遇到了这个问题。 我通过结合这里给出的其他答案和注释来解决它,以便为DNX 4.5.1和DNX Core 5.0提供交叉编译:

 "frameworks": { "dnx451": { "frameworkAssemblies": { "System.ComponentModel.DataAnnotations": "4.0.0.0" }, "dependencies": { } }, "dnxcore50": { "dependencies": { "System.ComponentModel.Annotations": "4.0.11-beta-23409" } } } 
  "frameworks": { "dnx451": { "frameworkAssemblies": { "System.ComponentModel.DataAnnotations": "4.0.0.0" }, "dependencies": { } } }