Azure Web Application Deployment: Web Deployment Cannot Modify the File at Destination because it is Blocked by an External Process

I use the "Azure Web App Deployment" build step in VSTS to publish the ASP.NET API for Azure Web App:

Azure Web Application Deployment

Sometimes this step is interrupted with the following error:

[error] Microsoft.Web.Deployment.DeploymentDetailedClientServerException: Web Deploy cannot change the file "MyProject.Api.exe" to because it is blocked by an external process. To enable the publish operation successfully, you may need to either restart your application to release the lock or use the AppOffline rule .Net application handler the next time you try to publish. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE .

This GitHub issue is causing the same issue, but there is no proposed solution using the Azure Web App deployment build step.

+10
source share
10 answers

According to a separate thread in the Microsoft Github repository, there is a hacking solution in which, if you add the following key to Azure Appsettings, it can help resolve the error when closing the file:

MSDEPLOY_RENAME_LOCKED_FILES = 1 

I'm not sure how long this cracker will be supported, but it helped me solve this problem personally.

enter image description here

+29
source

You can create two Power Shell scripts:

stopapp.ps1:

 param($websiteName) $website = Get-AzureWebsite -Name $websiteName Stop-AzureWebsite -Name $websiteName 

startapp.ps1:

 param($websiteName) $website = Get-AzureWebsite -Name $websiteName Start-AzureWebsite -Name $websiteName 

Then add the Azure PowerShell task before and after the Azure Web Application Deployment task to stop the web application before deployment and run the application after deployment. enter image description here

+7
source

I struggled with the same lock issue.
Now there are new tasks (in preview mode) that you can add to start and stop the application service:

enter image description here

Add a stop task before deployment and a start task after deployment.

enter image description here

It helped me.

+5
source

Taking the website offline upon release should do the trick.

enter image description here

+2
source

You can restart the Function application to unlock it. After that you can deploy.

enter image description here

+1
source

There are some dedicated tasks for asp.net core projects because the deployment process is a little different.
You can get them from the market for free, check DNX Tasks vsts marketplace
Hope this helps!

0
source

Eddie's answer was close to what I needed, the only thing missing was a way to specify a slot for deployment:

stopapp.ps1

 param($websiteName, $websiteSlot) $website = Get-AzureWebsite -Name $websiteName -Slot $websiteSlot Stop-AzureWebsite -Name $websiteName -Slot $websiteSlot 

startapp.ps1

 param($websiteName, $websiteSlot) $website = Get-AzureWebsite -Name $websiteName -Slot $websiteSlot Start-AzureWebsite -Name $websiteName -Slot $websiteSlot 

And then in your Azure PowerShell Script task, the arguments could be something like this:

 -websiteName "{mywebsite}" -websiteSlot "{mydeploymentslot}" 
0
source
  1. Stop application service
  2. deploy code
  3. Launch Application Service

enter image description here

0
source

I was getting the same error when trying to publish an Azure function app. I followed this Microsoft document and took the following steps.

  1. Right click on your project and select Edit .... csproj
  2. Add <EnableMSDeployAppOffline>true</EnableMSDeployAppOffline> to the PropertyGroup tag.

     <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> <AzureFunctionsVersion>v2</AzureFunctionsVersion> <EnableMSDeployAppOffline>true</EnableMSDeployAppOffline> </PropertyGroup> 
  3. Save and restore your decision

  4. Now publish again

If this did not work for you, you can always add MSDEPLOY_RENAME_LOCKED_FILES=1 as Mr. Ben mentioned in his answer to his application settings. You can do this from within Visual Studio itself.

enter image description here

enter image description here

Hope help

0
source

Adding stopping the application service and starting application service tasks worked for me

0
source

All Articles