dotnet ef 核心列表永远不会完成

dotnet ef core list never completes

通过 Azure Dev Ops 提交构建后,我们注意到构建迁移步骤的命令在闲置一小时后超时。它只发生在这个分支上,我们已经成功地完成了其他分支。解决方案构建成功并 运行s。

经过调查,我将问题缩小到在以下命令上发生:

dotnet ef migrations list --configuration Release --project <repo_project_name> --startup-project <startup_project_name> --no-build --context <fully_qualified_context_class_name>

当我 运行 在 Powershell 中执行上述命令时,它在吐出项目中的迁移列表后,它只是挂起并且永远不会 returns 提示。

我看到其他类似问题的讨论建议删除 obj 文件夹,但是当我在启动项目文件夹中这样做时,我收到一条消息,提示它缺少 project.assets.json。 (当我在 repo 项目文件夹中执行它时,它像以前一样挂起。但即使在本地解决了它,我如何在 ADO 服务器上实现它?

更奇怪的是,这个特定的分支甚至没有更新 repo 项目。

关于我应该如何进行的任何想法?谢谢

更新:我已经能够缩小我们正在等待线程结束的范围。这是它挂起时的调用堆栈:

System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOneNoCheck(int millisecondsTimeout)
System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout)
System.Diagnostics.Process.dll!System.Diagnostics.Process.WaitForExitCore(int milliseconds)
dotnet-ef.dll!Microsoft.EntityFrameworkCore.Tools.Exe.Run(string executable, System.Collections.Generic.IReadOnlyList<string> args, string workingDirectory, bool interceptOutput)
dotnet-ef.dll!Microsoft.EntityFrameworkCore.Tools.RootCommand.Execute()
dotnet-ef.dll!Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.Configure.AnonymousMethod__0()
dotnet-ef.dll!Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(string[] args)
dotnet-ef.dll!Microsoft.EntityFrameworkCore.Tools.Program.Main(string[] args)

问题原来是我们开发的进程在脚本生成后没有正常关闭。其原因似乎是“dotnet ef migrations”只对网站进行了部分启动。它调用 Startup.ConfigureServices 而不是 Startup.Configure,这是配置 Web 关闭函数的地方,所以我推测 Dispose 方法没有被正确调用,导致我们的进程没有正确关闭。

我通过对另一个问题实施 this answer 中的建议来解决这个问题。