When trying to scaffold with asp.net core this command
scaffold-dbcontext \"Data Source=(local);Initial Catalog=MyDb;Integrated Security=True;\" M
Scaffold command is part of dbcontext command in EF. Below are the details for successful scaffold:
Package references required:
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0"/>
So our scaffold command should look like:
dotnet ef dbcontext scaffold "Server=localhost\SQLEXPRESS;Database=MyDatabase;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o OutputDirectory
Your Server value might differ as per your Db server name. Replace MyDatabase with your Database name like master and OutputDirectory to the location you want your newly created scaffolded classes like Models folder.
I ran into another cause of this error recently: NuGet itself was out of date.
Updating NuGet resolved the issue.
If Devanathan's answer doesn't work for you, check to make sure NuGet itself is up to date.
I had installed Microsoft.EntityFrameworkCore.Tools from NuGet Package Manager and it was visible in the installed packages. But I kept getting this error.
Restarting Visual Studio (2019/Version 16.4.4) fixed it for me.
Make sure you run VS as Administrator and have installed the following packages: