1

How can i run the following command from the code

i have tried the following but not worked

System.Diagnostics.Process.Start("CMD.exe", @"dotnet ef dbcontext scaffold ""server=xxx.xxx.x.xxx;user=xxxxx;database=dbname;port=3306;Password=xxxxx;Allow User Variables=True;"" Pomelo.EntityFrameworkCore.MySql -t customers -o ModelsFolderNam");

but if i run it in package console then it will scaffold tables succesfully

khaled saleh
  • 470
  • 7
  • 18
  • When something doesn't work, you need to tell us why it didn't work. Did you get errors? What were they? What output did you expect? What output did you get? Also, why are you trying to run this command via C# in the first place? – DavidG Jun 09 '22 at 09:10
  • no errors appeared, i need to create an mvc project to scaffold db entities (user-friendly) one – khaled saleh Jun 09 '22 at 09:36
  • it's not working for me as well, did you manage to solve it? – Vadim Tomashevsky May 04 '23 at 09:18

1 Answers1

1

This is because in order to scaffold your context, you have to be in your .NET project path. By default cmd opens in C:\Users\yourWinUserName> or if you open cmd directly as administrator that would be: C:\WINDOWS\system32>

Navigate to your project first, then perform scaffold. Here you can find how to perform that type of navigation in single command: How can I open a cmd window in a specific location?

Azelski
  • 155
  • 1
  • 2
  • 10