Question:
Wondering if anyone can help me solve this.
I am able to use the Package Manager Console to Enable-Migrations, Add-Migrations etc etc. But I want to be able to do this using c# code via the PowerShell object
What I have so far is:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
var ps = PowerShell.Create(); ps.AddCommand("Set-ExecutionPolicy"); ps.AddArgument("Unrestricted"); ps.AddCommand("Import-Module"); ps.AddParameter("Name"); ps.AddArgument(@"'.\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1'"; ps.AddCommand("Add-Migration"); ps.AddParameter("Name"); ps.AddArgument("Migration21Sept"); ps.AddParameter("ProjectName"); ps.AddArgument("Context1"); ps.Invoke(); |
But when I execute this code I get an error stating: “The term ‘Add-Migration’ is not recognized as the name of a cmdlet, function, script file, or operable program”
Answer:
Browse to your entity directory, shift + right click then select “Open powershell window here”
dotnet ef migrations add “MigrationName”