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

2.1k views Asked by At

Actual

Release pipeline fails when deploying

Expected

Deploy does not fail

Root cause

File 'Microsoft.Data.SqlClient.SNI.x86.dll' is locked locked by an external process, even when 'Take App Offline Flag' setting is on

Workaround

Recycle application pool manually and rerun failed deploy.

Trying to automate the recycle also failed when applying the 'Action IIS Application Pool' setting with 'recycleAppPool'.

Information

Error message

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.
2

There are 2 answers

0
pembr On BEST ANSWER

For those who aren't using the Azure App Service yet.

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

[deploy application here]

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

More information: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/iis-web-app-management-on-machine-group?view=azure-devops

3
Leo Liu On

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

You could add two task, a stop app service task before deployment and a start app service task after the deployment:

enter image description here

- 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

And you could also try to configure the appOffline rule in the publishing profile (.pubxml). Add the EnableMSDeployAppOffline element to the PropertyGroup like this:

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

Please check this document ERROR_FILE_IN_USE and this thread for some more details.