I'm currently working on an ASP.Net Core project and I'm encountering an issue when trying to execute the following command:
dotnet ef dbcontext scaffold "MyConnectionString" Microsoft.EntityFrameworkCore.SqlServer -o Entities
I keep getting the error: "command or file not found." I'm using visual studio 2022 with EF 6.0 and SqlServer 2019.
I verified that the Entity Framework Core tools are installed using dotnet tool list -g
.
Also I checked the project file to ensure the EF Core packages are correctly referenced:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.36">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.36" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.36">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Ran dotnet restore
to ensure all packages are restored.
Despite these steps, I'm still encountering the issue. Has anyone faced a similar problem or have any suggestions on what might be causing this and how to resolve it?
If you are using .NET 9, you can fix it via the command below.
dotnet tool install --global dotnet-ef --version 9.*
.NET 8
dotnet tool install --global dotnet-ef --version 8.*
.NET 6
dotnet tool install --global dotnet-ef --version 6.*