我遇到了相同的问题。我已经在我的project.json
文件中添加了以下依赖项:
"dependencies": {
"EntityFramework": "7.0.0-beta4",
"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.SqlServer": "7.0.0-beta8",
"EntityFramework.Commands": "7.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},
...
我使用了dnu install EntityFramework
和dnu install EntityFramework.SqlServer
来安装这些包。 安装程序会在dependencies
节点下自动写入"EntityFramework": "7.0.0-beta4"
。
问题1:让我惊讶的是,当我拉取EntityFramework
的智能感知时,我看到的可用版本仅为6.1.3
!
问题2:当我使用dnu build
编译我的应用程序时(手动将EntityFramework
程序集(.Core
和.Commands
)添加到dependencies
节点后运行了dnu restore
命令),我得到了一堆编译错误:
The type 'DbContextOptionsBuilder' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null'.
D:\Projects\aspnet\apiservice\Models\SampleData.cs(12,41): DNXCore,Version=v5.0 error CS0308: The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments
D:\Projects\aspnet\apiservice\Models\SampleData.cs(13,32): DNXCore,Version=v5.0 error CS0308: The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments
D:\Projects\aspnet\apiservice\Models\SampleData.cs(14,29): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'Books' and no extension method 'Books' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
D:\Projects\aspnet\apiservice\Models\SampleData.cs(15,42): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'Authors' and no extension method 'Authors' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
D:\Projects\aspnet\apiservice\Models\SampleData.cs(17,43): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'Authors' and no extension method 'Authors' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
D:\Projects\aspnet\apiservice\Models\SampleData.cs(19,45): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'Authors' and no extension method 'Authors' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
D:\Projects\aspnet\apiservice\Models\SampleData.cs(22,29): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'Books' and no extension method 'Books' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
D:\Projects\aspnet\apiservice\Models\SampleData.cs(61,29): DNXCore,Version=v5.0 error CS1061: 'object' does not contain a definition for 'SaveChanges' and no extension method 'SaveChanges' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
如果我删除.Core
和.Commands
程序集引用,则项目将能够成功构建。
然后,根据错误信息,我更改了EntityFramework.Core
的版本为7.0.0.0
:
The type 'DbContextOptionsBuilder' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null'.
但是现在dnu restore
给了我以下结果:
Unable to locate Dependency EntityFramework.Core >= 7.0.0
Writing lock file D:\Projects\aspnet\apiservice\project.lock.json
Restore complete, 6675ms elapsed
Errors in D:\Projects\aspnet\apiservice\project.json
Unable to locate Dependency EntityFramework.Core >= 7.0.0
我是一个asp.net 5
Visual Studio Code
平台的新手。由于团队中其他成员使用OSX操作系统,我无法使用Visual Studio 2015
。
这对我来说是一个学习项目,要求非常简单。连接SQL Server数据库,并使用Entity Framework获取主-从
关系数据。
出了点问题!求救!!
先谢谢了
更新
我可以看到所有版本为
7.0.0-rc1-final
的包在project.json
中有重大更改。我使用Yeoman生成器工具创建了项目,但似乎您通过Visual Studio
进行了包的更正。那么,我需要手动更新包版本并还原
它们吗?当使用Yeoman创建/生成项目时,默认情况下没有添加
global.json
文件。我可以手动添加这个文件并手动放置代码吗?这样会有效果吗?我还可以看到一些额外的包引用被添加到
project.json
文件中,这些包不是Yeoman生成器自动添加的 - 比如Microsoft.AspNet.Tooling.Razor
、Microsoft.Extensions.Logging.Console
、Microsoft.Extensions.Logging.Debug
、Microsoft.Extensions.Logging
等。它们在项目中有效吗?因为生成器没有自动添加它们,所以我可以手动添加它们并使用dnu restore
进行还原吗?如果我手动添加它们,会对项目产生影响吗?