运行dotnet工具还原以使dotnet-ef命令可用

问题描述 投票:0回答:1

我在发布配置文件中使用Visual Studio和EF迁移时遇到了非常奇怪的情况。给出:

  • Visual Studio 2019 v16.4
  • 。NET Core项目。目标.NET Core 3.1
  • EF 3.1
  • Azure发布个人资料

我已经在本地项目中创建了迁移,并且尝试在发布配置文件中枚举迁移时,得到了

Run dotnet tool restore to make the dotnet-ef command available

enter image description here

我不知道此错误意味着什么,因为似乎安装了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>

最后一行没有任何改变。我可以使用PS命令,例如Add-MigrationUpdate-Database或cmd命令,例如dotnet ef migrations adddotnet ef database updatedotnet-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" />
<...>

[UI项目仅引用Design

<...>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<...>

周围有很多类似的问题,例如:Cannot list Entity Framework Migrations in Visual Studio 2019 due to dotnet ef dbcontext --json failure

似乎他们的常见问题是他们没有安装工具,因为dotnet ef命令不再是.NET Core SDK的一部分,而我也不是这种情况,因为安装了本地EF工具并可以从命令行使用它们。

entity-framework asp.net-core .net-core ef-migrations dotnet-tool
1个回答
0
投票

(对不起,我没有足够的声誉来发表评论)我有与您完全相同的问题,我没有找到解决方案,但是我在另一台计算机上进行了测试,并且发布正常。我不明白为什么,因为我尝试卸载我自己计算机上的所有.net组件,并且更改没有发生。我认为这可能是nuget包的问题,​​但我真的不知道

© www.soinside.com 2019 - 2024. All rights reserved.