PowerShell 命令通过代码添加 EF 迁移

mic*_*a_p 5 c# powershell entity-framework entity-framework-migrations powershell-cmdlet

想知道是否有人可以帮我解决这个问题。

我可以使用包管理器控制台来启用迁移、添加迁移等。但我希望能够通过 PowerShell 对象使用 C# 代码来完成此操作

到目前为止我所拥有的是:

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();
Run Code Online (Sandbox Code Playgroud)

但是,当我执行此代码时,出现错误:“术语‘Add-Migration’未被识别为 cmdlet、函数、脚本文件或可操作程序的名称”

小智 -1

浏览到您的实体目录,按住 Shift 键并右键单击,然后选择“在此处打开 powershell 窗口”

dotnet ef 迁移添加“MigrationName”