I'm having a quite strange situation with Visual Studio and EF migrations in Publish Profile. Given:
- Visual Studio 2019 v16.4
- .NET Core project. Targets .NET Core 3.1
- EF 3.1
- Azure publish profile
I've created migrations in local project and when trying to enumerate migrations in publish profile, I get
Run dotnet tool restore to make the dotnet-ef command available
I don't know what this error means, because dotnet-ef tools seems installed:
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>
Last line doesn't change anything. I can use PS commands such as Add-Migration
, Update-Database
, or cmd commands such as dotnet ef migrations add
, dotnet ef database update
. dotnet-ef <...>
work as well. The only place where they don't work -- publish profile settings. I can't enable checkbox to run migrations on publish.
Data
project has referenced these EF-related packages:
<...>
<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
project references only Design
:
<...>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<...>
There are lots of similar questions around, like this: Cannot list Entity Framework Migrations in Visual Studio 2019 due to dotnet ef dbcontext --json failure
It seems their common issue is that they didn't have tools installed, because dotnet ef
commands are no longer parts of .NET Core SDK and it is not my case, since local EF tools are installed and work from command line.