Cry*_*t32 5 entity-framework .net-core asp.net-core dotnet-tool entity-framework-migrations
我在发布配置文件中遇到 Visual Studio 和 EF 迁移的非常奇怪的情况。鉴于:
我已经在本地项目中创建了迁移,当尝试在发布配置文件中枚举迁移时,我得到
Run dotnet tool restore to make the dotnet-ef command available
Run Code Online (Sandbox Code Playgroud)
我不知道这个错误意味着什么,因为似乎安装了 dotnet-ef 工具:
PM> dotnet --version
3.1.101
PM> dotnet ef --version
Entity Framework Core .NET Command-line Tools
3.1.1
PM> dotnet ef dbcontext list --json --project MyUIProject
Build started...
Build succeeded.
[
{
"fullName": "MyDataProject.MyDbContext",
"safeName": "MyDbContext",
"name": "MyDbContext",
"assemblyQualifiedName": "MyDataProject.MyDbContext, MyDataProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
}
]
PM> dotnet tool restore
Restore was successful.
PM>
Run Code Online (Sandbox Code Playgroud)
最后一行没有改变任何东西。我可以使用 PS 命令,如Add-Migration、Update-Database,或 cmd 命令,如dotnet ef migrations add、dotnet ef database update。dotnet-ef <...>工作也一样。它们唯一不起作用的地方是发布配置文件设置。我无法启用复选框来在发布时运行迁移。
Data项目引用了这些EF相关的包:
<...>
<PackageReference Include="microsoft.aspnetcore.Identity.EntityFrameworkCore" Version="3.1.1" />
<PackageReference Include="microsoft.EntityFrameworkCore" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Data.SqlClient" Version="4.8.0" />
<...>
Run Code Online (Sandbox Code Playgroud)
UI仅供项目参考Design:
<...>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<...>
Run Code Online (Sandbox Code Playgroud)
周围有很多类似的问题,例如:Cannot list Entity Framework Migrations in Visual Studio 2019 due to dotnet ef dbcontext --json failure
他们的常见问题似乎是没有安装工具,因为dotnet ef命令不再是 .NET Core SDK 的一部分,而且这不是我的情况,因为本地 EF 工具已安装并通过命令行工作。
我找到了2种方法
尝试以管理员身份运行 Visual Studio。
如果 (1.) 不起作用,请在项目中输入dotnet new tool-manifest, dotnet tool install dotnet-ef, dotnet tool restore。
描述
不知何故,Visual Studio 无法访问安装了全局包的 C://Users/AlexanderK/.nuget。我们的电脑上可能有某些软件阻止 Visual Studio 访问全局安装的包。我不确定 nuget 是如何工作的,但 Nodejs 的 npm 可以在本地和全局安装的包中进行搜索。因此,在我们的 Visual Studio 案例中,本地没有安装 dotnet-ef,但无法全局访问它。
在(1.)中,我们以管理员身份运行,并尝试授予 Visual Studio 访问全局安装的软件包的权限。
在 (2.) 中,我们在本地安装 dotnet-ef,因此 nuget 肯定会在本地找到该包。
有关dotnet tool命令的更多信息 -官方文档
我建议您使用(1.),因为大多数 PC 不会出现这个问题,并且当您在全球范围内安装像 dotnet-ef 这样的软件包时,在本地安装它并不是一个好主意。
检查您安装了哪些 .NET Core SDK 平台版本...32 位或 64 位或两者。
如果您两者都有,我认为 VS2019 将使用它首先找到的任何内容,这可能不是您安装的 EF Core 工具。
| 归档时间: |
|
| 查看次数: |
12012 次 |
| 最近记录: |