Azure 发布管道 (YAML) IIS Web 部署在生成 ERROR_FILE_IN_USE 的锁定文件上失败

Azure release pipeline (YAML) IIS web deploy fails on locked files generating ERROR_FILE_IN_USE

实际

部署时发布管道失败

预计

部署没有失败

根本原因

文件 'Microsoft.Data.SqlClient.SNI.x86.dll' 被外部进程锁定,即使 'Take App Offline Flag' 设置已打开

解决方法

手动回收应用程序池并重新运行失败的部署。

在 'recycleAppPool' 中应用 'Action IIS Application Pool' 设置时,尝试自动回收也失败了。

信息

错误信息

Error Code: ERROR_FILE_IN_USE More Information: Web Deploy cannot modify the file 'Microsoft.Data.SqlClient.SNI.x86.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: The process cannot access the file because it is being used by another process.

Azure release pipeline (YAML) IIS web deploy fails on locked files generating ERROR_FILE_IN_USE

您可以添加两个任务,部署前停止应用服务任务和部署后启动应用服务任务:

- task: AzureAppServiceManage@0
  displayName: 'Stop Azure App Service: tomsun'
  inputs:
    azureSubscription: 'xxxx'
    Action: 'Stop Azure App Service'
    WebAppName: xxxx


- task: AzureAppServiceManage@0
  displayName: 'Stop Azure App Service: tomsun'
  inputs:
    azureSubscription: 'xxxx'
    Action: 'Restart Azure App Service'
    WebAppName: xxxx

您也可以尝试在发布配置文件中配置 appOffline 规则 (.pubxml)。将 EnableMSDeployAppOffline 元素添加到 PropertyGroup,如下所示:

<PropertyGroup>
  <EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
</PropertyGroup>

请查看此文档ERROR_FILE_IN_USE and this thread了解更多详情。

对于尚未使用 Azure 应用服务的用户。

      - task: IISWebAppManagementOnMachineGroup@0
        displayName: Stop AppPool
        inputs:
          IISDeploymentType: 'IISApplicationPool'
          ActionIISApplicationPool: 'StopAppPool'
          StartStopRecycleAppPoolName: '$(AppPoolName)'  

[在此处部署应用程序]

      - task: IISWebAppManagementOnMachineGroup@0
        displayName: Start AppPool
        inputs:
          IISDeploymentType: 'IISApplicationPool'
          ActionIISApplicationPool: 'StartAppPool'
          StartStopRecycleAppPoolName: '$(AppPoolName)'

更多信息: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/iis-web-app-management-on-machine-group?view=azure-devops