Azure Devops:如何使用“IIS Web 应用程序部署”任务启用重命名锁定文件 (RenameFilesFlag)

问题描述

当我尝试在 Azure Devops 中使用发布管道进行部署时,我遇到了锁定 DLL 文件的问题。

错误截图为:

enter image description here

输出为文本:

2021-03-31T17:43:18.2626492Z ##[error]Error Code: ERROR_FILE_IN_USE
More information: Web Deploy cannot modify the file 'Microsoft.Data.sqlClient.SNI.x64.dll' 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.
    Error count: 1.

问题似乎是由错误处理的 .NET 资源引起的。 (例如:非托管 sqlConnection) 反正我改不了源代码

这是我的发布管道。

Azure Devops Release Deploy

这是我的问题:

Q1) 我正在尝试使用“-RenameFilesFlag”(MSDEPLOY_RENAME_LOCKED_FILES),如下所述:

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment?view=azure-devops

web.config file locked during Azure App Service Deploy task

我必须如何指定这个参数? 我是否必须填写“附加参数”文本框?我尝试了不同的值,但总是得到一个 “无法识别的参数”错误

Q2) 如果“-RenameFilesFlag”不适用于此任务。 我可以使用“Take App Offline”来解锁文件吗?

Q3) 在 StackOverflow 上的另一篇文章中,我看到了一个特定于“重命名锁定文件”的复选框选项 Getting ERROR_FILE_IN_USE while using Web Deploy in Azure App Service Task v3

我的任务中没有这个选项。我是否可能混淆了两种部署任务?

解决方法

MSDEPLOY_RENAME_LOCKED_FILES

据我所知,这种方式只支持Azure Web APP服务。此选项用于设置 Azure 应用设置(云)。它不适用于 IIS 部署(本地)。

##[error]错误代码:ERROR_FILE_IN_USE

要解决此问题,您可以尝试以下方法:

1.您可以在 IIS Web 部署任务中设置 Take App Offline 选项。

enter image description here

这是关于 Taking an Application Offline before Publishing

的文档

2.您可以在部署应用程序之前停止您的网站,并在部署后重新启动它。

您可以添加 IIS web app manage task 来停止和启动 IIS 网站。

例如:

enter image description here

更新 1:

正如 ssinfod 的评论:停止应用程序池可以解决这个问题。

我们也可以在 IIS web app manage task

中实现这一点

enter image description here