I have a site that was built using database first and I'm trying to continue development of it on a mac. Normally I would run the Scaffold-dbContext using the Console Package Manager in Visual Studio. The mac version doesn't have this I tried running it in Terminal, but that obviously didn't work. Is it possible to run this command, or do I need to continue development on Windows?
-
Did you get to the bottom of this? Same problem.. – saZmer Jun 23 '17 at 18:42
-
No, I just went back to developing on Windows. – Jhorra Jun 24 '17 at 20:22
-
I'm having the same problem. I'm using High Sierra 10.13.5 and VS Community 7.5.3 (build 7). I'm added the entry: DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" on .csproj, opened de solution and restored NuGet packages. But it did't added on my project and the Console is unable to write any word. Some idea? – Jean J. Michel Jul 06 '18 at 01:03
4 Answers
Here is the code work for me on visual studio mac
Install the below package using visual studio mac edit references on project or add package to .csproj file.
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Microsoft.VisualStudio.Web.CodeGeneration.Design
or using the Terminal navigate to the project and use the below command -
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
Now check the tools and EF are installed or not.Navigate to the project install location and use mac terminal with below command. It should show entity framework details
dotnet ef
Now Scaffold the DB context
dotnet ef dbcontext Scaffold "Server=<servername>,1433;Initial Catalog=<dbName>;Persist Security Info=False;User ID=<userID>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"Microsoft.EntityFrameworkCore.SqlServer -o <directory name>
References
https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet
https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db
https://www.learnentityframeworkcore.com/walkthroughs/existing-database

- 15,327
- 34
- 171
- 290
-
I'm marking this as the answer. This wasn't possible when I first asked the question, but with the update to .Net Core 2.0, this answer gives all the necessary info and steps required to do this on a mac. – Jhorra Apr 02 '19 at 05:41
-
2See https://stackoverflow.com/a/57070108/266553 - `dotnet ef` is now a separate tool, `dotnet-ef`. Also, in the scaffold command there should be a space between the closing quote and `Microsoft.EntityFrameworkCore.SqlServer` – KenD Mar 29 '21 at 12:30
-
1The above command work for me after using this command `dotnet tool install --global dotnet-ef` ... I already installed this ... but didn't work until run with the --global flag... – Wahab Khan Jadon Jul 25 '22 at 14:07
-
@WahabKhanJadon - you are abs right, that is why the answer must NOT be marked as correct. – Alex Sham Aug 15 '23 at 20:38
You can run the command from the terminal after completing a few required steps as found here:
- You need to add the following manually to your *.csproj
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
- Execute
dotnet add package Microsoft.EntityFrameworkCore.Design
3.Execute
dotnet restore
You should now be able to scaffold using the command:
dotnet ef dbcontext scaffold --help

- 246
- 3
- 5
I just wanted to post my solution after I struggled for a while. Had to separate the schema string into multiple --schema options.
dotnet ef dbcontext scaffold "Server=<servername>,1433;Initial Catalog=<dbName>;Persist Security Info=False;User ID=<userID>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" Microsoft.EntityFrameworkCore.SqlServer --context [context] -f --output-dir [dir] --schema [schema1] --schema [schema2]

- 21
- 1
If you are using .NET Core 3.0.0 even after installing EntityFrameworkCore you will need to run
dotnet add package Microsoft.EntityFrameworkCore.SqlServer

- 123
- 6