.NET 实体框架核心 [英] .NET Entity Framework Core
问题描述
我已经阅读了过去 2 年中发布的几乎所有关于 EF 的其他问题.我下载其他软件包没有问题,只有 Entity Framework 不会为我安装.
我什至尝试安装最新版本的 Nuget 并在我的项目目录中使用它的工具来恢复包 - 之后 - 我在我的 .csproj 中添加了这一行:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2"/>
首先我尝试了这个命令:
dotnet 还原
输出这个:
C:PathToMyProject>dotnet restoreC:PathToMyProjectTestNuget.csproj 的还原在 100.41 毫秒内完成.C:PathToMyProjectTestNuget.csproj 的还原在 68.84 毫秒内完成.
结果如下:
>dotnet ef找不到与命令dotnet-ef"匹配的可执行文件
然后我尝试了这个(使用截至今天日期的最新版本的 Nuget):
nuget restore Example.csproj
输出这个:
MSBuild 自动检测:使用来自C:Program Files (x86)Microsoft Visual Studio2017CommunityMSBuild15.0in"的 msbuild 版本15.6.85.37198".提交还原...工具资产文件没有改变.跳过资产文件写入.路径:C:PathToNuget.nugetpackages.toolsmicrosoft.visualstudio.web.codegeneration.tools2.0.3
etcoreapp2.0project.assets.jsonC:PathToUsersource
eposExampleExampleExample.csproj 的还原在 139.95 毫秒内完成.提交还原...资产文件没有改变.跳过资产文件写入.路径:C:PathToUsersource
eposExampleExampleobjproject.assets.jsonC:PathToUsersource
eposExampleExampleExample.csproj 的还原在 113.51 毫秒内完成.使用的 NuGet 配置文件:C:PathToUserAppDataRoamingNuGetNuGet.ConfigC:Program Files (x86)NuGetConfigMicrosoft.VisualStudio.Offline.configC:Program Files (x86)NuGetConfigMicrosoft.VisualStudio.Offline.Fallback.config使用的饲料:C:Program Files (x86)Microsoft SDKsNuGetPackageshttps://api.nuget.org/v3/index.json
结果相同.
我完全不确定问题是什么,我在网上阅读的所有内容,包括 https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet声明您所要做的就是更改 .csproj 文件并使用 dotnet/nuget 包管理工具进行恢复,但这似乎对我的项目没有任何作用,并且仍然找不到 dotnet-ef.exe.
我做了以下操作,效果很好,
- 创建一个新的 .NET Core MVC Web 应用程序
- 转到命令提示符,更改dir 到您的应用程序项目文件夹
- 执行以下命令
<块引用>
dotnet 添加包 Microsoft.EntityFrameworkCore.Designdotnet 还原
以上命令执行完毕后,在 .csproj 文件中包含以下几行(就在关闭 Project 标记之前)
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0"/></项目组>
完整的 .csproj 文件可能如下所示,
<属性组><TargetFramework>netcoreapp2.0</TargetFramework></PropertyGroup><项目组><PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6"/><PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2"/></项目组><项目组><DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3"/></项目组><项目组><DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0"/></项目组></项目>
输入dotnet ef
如果所有配置都没有问题,你会看到如下响应
_/\__---==/\___ ___ |.||__||__||) \|_||_|\_/|//|\|___|||_|/\/\实体框架核心 .NET 命令行工具 2.0.0-rtm-26452用法:dotnet ef [选项] [命令]选项:--version 显示版本信息-h|--help 显示帮助信息-v|--verbose 显示详细输出.--no-color 不要着色输出.--prefix-output 带有级别的前缀输出.命令:database 管理数据库的命令.dbcontext 管理 DbContext 类型的命令.migrations 管理迁移的命令.使用dotnet ef [command] --help"获取有关命令的更多信息.
I've already read through pretty much every other issue regarding EF in that was posted in the past 2 years. I have had no problems downloading other packages, it's only Entity Framework that will not install for me.
I've even tried installing the latest version of Nuget and using it's tool inside of my project directory to restore the packages -after- I added a this line to my .csproj:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
First I tried this command:
dotnet restore
which output this:
C:PathToMyProject>dotnet restore
Restore completed in 100.41 ms for C:PathToMyProjectTestNuget.csproj.
Restore completed in 68.84 ms for C:PathToMyProjectTestNuget.csproj.
and results in this:
> dotnet ef
No executable found matching command "dotnet-ef"
So then I tried this (using the latest version of Nuget as of today's date):
nuget restore Example.csproj
which outputs this:
MSBuild auto-detection: using msbuild version '15.6.85.37198' from 'C:Program Files (x86)Microsoft Visual Studio2017CommunityMSBuild15.0in'.
Committing restore...
Tool assets file has not changed. Skipping assets file write. Path: C:PathToNuget.nugetpackages.toolsmicrosoft.visualstudio.web.codegeneration.tools2.0.3
etcoreapp2.0project.assets.json
Restore completed in 139.95 ms for C:PathToUsersource
eposExampleExampleExample.csproj.
Committing restore...
Assets file has not changed. Skipping assets file writing. Path: C:PathToUsersource
eposExampleExampleobjproject.assets.json
Restore completed in 113.51 ms for C:PathToUsersource
eposExampleExampleExample.csproj.
NuGet Config files used:
C:PathToUserAppDataRoamingNuGetNuGet.Config
C:Program Files (x86)NuGetConfigMicrosoft.VisualStudio.Offline.config
C:Program Files (x86)NuGetConfigMicrosoft.VisualStudio.Offline.Fallback.config
Feeds used:
C:Program Files (x86)Microsoft SDKsNuGetPackages
https://api.nuget.org/v3/index.json
Which has the same results.
I'm not at all sure what the problem is, everything I'm reading online, including https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet is stating that all you have to do is a alter the .csproj file and restore using the dotnet/nuget package managing tool, but this seems to do absolutely nothing to my project, and dotnet-ef.exe is still no where to be found.
I did the following and it works,
- Create a new .NET Core MVC Web App
- Go to command prompt, change the dir to your application project folder
- Execute the following command
dotnet add package Microsoft.EntityFrameworkCore.Design dotnet restore
After the above commands are executed, Include the below lines in your .csproj file (just before the closing Project tag)
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
The complete .csproj file may look like as below,
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
</Project>
Type dotnet ef
If all the configurations are fine, you will see the following response
_/\__
---==/ \
___ ___ |. |
| __|| __| | ) \
| _| | _| \_/ | //|\
|___||_| / \/\
Entity Framework Core .NET Command Line Tools 2.0.0-rtm-26452
Usage: dotnet ef [options] [command]
Options:
--version Show version information
-h|--help Show help information
-v|--verbose Show verbose output.
--no-color Don't colorize output.
--prefix-output Prefix output with level.
Commands:
database Commands to manage the database.
dbcontext Commands to manage DbContext types.
migrations Commands to manage migrations.
Use "dotnet ef [command] --help" for more information about a command.
这篇关于.NET 实体框架核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!