9

所以在这里我们试图在比赛前掌握 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 会抱怨?

4

3 回答 3

9

我刚刚遇到了 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"
    }
  }
}
于 2015-10-28T12:04:16.433 回答
4

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

用于在您的项目中使用数据注释Microsoft.DataAnnotations代替System.ComponantModel.DataAnnotations.

于 2015-05-27T04:18:34.793 回答
1
  "frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System.ComponentModel.DataAnnotations": "4.0.0.0"
      },
      "dependencies": {
      }
    }
  }
于 2015-07-07T02:54:53.007 回答