问题描述
通过Azure Dev Ops提交构建后,我们注意到一个小时不活动后,用于构建迁移步骤的命令就会超时。它仅在此分支上发生,并且自成功以来,我们已经完成了其他任务。该解决方案可以构建并成功运行。
在调查后,我将问题缩小为以下命令:
dotnet ef migrations list --configuration Release --project <repo_project_name> --startup-project <startup_project_name> --no-build --context <fully_qualified_context_class_name>
当我在Powershell中运行以上命令时,它吐出了项目中的迁移列表后,它只是挂起,从不返回提示。
我还看到了其他类似的讨论,建议删除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迁移”仅会部分启动网站。它调用的是Startup.ConfigureServices而不是Startup.Configure,后者是配置Web关闭功能的位置,因此我认为没有正确调用Dispose方法,导致我们的过程无法正确关闭。
我通过将this answer中的建议应用于另一个问题来解决此问题。