asp.net - 用于应用 Entity Framework 迁移的 PowerShell?

标签 asp.net entity-framework powershell migration

我正在使用 PowerShell 来应用 EF 迁移。它正在工作,唯一的问题是如果应用迁移时出现任何错误,它仍然会成功。如果应用迁移时出现任何错误,我希望能够抛出异常。找不到任何关于如何做到这一点的信息。这是我的脚本:

  try
 {
#all relative paths are relative to where xyzabc.sln is

#copy migrate.exe to xyzabcWebRole\bin
Copy-Item packages\EntityFramework*\tools\migrate.exe xyzabc\path\xyzabcWebRole\bin -ErrorAction "Stop"

#migrate 
$migrator = "C:\TeamCity\buildAgent\work\f791999b69d7a83e\packages\EntityFramework.6.1.3\tools\migrate.exe" 
$migrateCommand = "$migrator xyzabcWebRole.dll /StartUpDirectory=C:\TeamCity\buildAgent\work\f791999b69d7a83e\xyzabcWebRole\bin /connectionStringName:MyDBConnectionString /startUpConfigurationFile:C:\TeamCity\buildAgent\work\f791999b69d7a83e\xyzabc\path\xyzabcWebRole\Web.config /verbose"  

Write-Host $migrateCommand
Invoke-Expression $migrateCommand


}
  catch [System.Exception]
{
Write-Host $_.Exception.ToString()
exit 1
}

最佳答案

调用迁移后检查 $LASTEXITCODE 变量并引发异常

关于asp.net - 用于应用 Entity Framework 迁移的 PowerShell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37795041/

相关文章:

powershell - 使用 Powershell 删除数组中定义的文件

git没有在powershell中运行

asp.net - 如何在route.config中订购多个路由?

c# - 我如何将 AllowHtml 属性与 Entity Framework 一起使用

c# - 使用 LINQ to Entities 的外连接查询

c# - 从查询字符串开始时比较 EntitySQL 中的 DateTime 值

powershell - 使用 PowerShell 创建硬链接(hard link)和软链接(soft link)

javascript - 使用 Javascript 在同一页面上查看全尺寸图像

c# - ASP.NET 母版页的动态变化

c# - 从 3.1.4 范围更新身份服务器 4 4.0.0 后,使用 Mongo DB 的 asp.net core 3 无效