在 Azure 应用服务任务 v3 中使用 Web 部署时获取 ERROR_FILE_IN_USE

Getting ERROR_FILE_IN_USE while using Web Deploy in Azure App Service Task v3

类似的问题已被问过多次,但大多数答案都是旧的,可​​能只部分适用。此问题特定于使用“Azure App Service Deploy”任务通过 Azure DevOps/Azure 管道使用 Web 部署,版本 3.*.

Failed to deploy web package to App Service.

Try to deploy app service again with Rename locked files option selected.

Error Code: ERROR_FILE_IN_USE

More Information: Web Deploy cannot modify the file 'VBCSCompiler.exe' on the destination because it is locked by an external process. In order to allow the publish operation to succeed, you may need to either restart your application to release the lock, or use the AppOffline rule handler for .Net applications on your next publish attempt. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE.

那里有两个建议:

  1. Select“重命名锁定的文件”选项
  2. 重新启动应用程序
  3. 使用 AppOffline 规则

此外,the documentation 该任务同时重申了建议 1 和 3。

For avoiding deployment failure with error code ERROR_FILE_IN_USE, in case of .NET apps targeting Web App on Windows, ensure that 'Rename locked files' and 'Take App Offline' are enabled. For zero downtime deployment use slot swap.

但是,这些建议已经到位。

剩下的就是建议2:重启服务。由于很多原因,我宁愿不必退回到这个。

为什么 1 和 3 不足以成功完成部署?

此处跟踪了一个问题:Azure App Service Deploy fails for .net core 2.0 with ERROR_FILE_IN_USE and based on vincentdass's comment "PR #8457根据 Web 部署团队的建议使用新版本的 MSDeploy。”未来版本中将对 msdeploy 进行升级。

但是您可以只检查 Publish Using Web DeployRename Locked Files,然后创建一个 new 部署。重新部署将不起作用,因为它不会获取您对发布定义所做的更改。

参考以下线程,您可以查看有关此问题的讨论并进行相应的故障排除。

我与 Microsoft 支持代表交谈,被告知 "Rename locked files" 仅适用于 DLL。

但我确实找到了适合我的解决方案。在 "Additional arguments" 中,我添加了“-useChecksum”。所以 "Deploy Azure App Service" 任务现在看起来像这样

从那以后我没有遇到任何问题。