3
votes

I'm using Right-Click publish in Visual Studio to publish directly to my staging slot in Azure. I've added Application Insights that added a WebJob to my app.

I have enabled Remove additional files at destination and Precompile during Publishing turned on.

But when a Web Job is running and my staging site is not 'stopped', because it's still warmed up - I get the following error:

Web deployment task failed. ((18-Jan-18 22:47:23) An error occurred when the request was processed on the remote computer.)

(18-Jan-18 22:47:23) An error occurred when the request was processed on the remote computer. An error was encountered when processing operation 'Delete Directory' on 'D:\home\site\wwwroot\App_Data\jobs\continuous'. The error code was 0x80070091. The directory is not empty.

at Microsoft.Web.Deployment.NativeMethods.RaiseIOExceptionFromErrorCode(Win32ErrorCode errorCode, String maybeFullPath) at Microsoft.Web.Deployment.DirectoryEx.Delete(String path) at Microsoft.Web.Deployment.DirPathProviderBase.Delete(Boolean whatIf) ProjectX.Web 7 0

I can fix this by manually stopping the staging slot, upload it, and then start it again. This is quite cumbersome though.

Is there a fix?

I read somewhere that you can automatically take the (staging) app offline during publish but I can't find the setting.

UPDATE 1

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

...is not working for me.

UPDATE 2

Adding the WEBJOBS_STOPPED setting on the Staging slot is not working for me.

2
Did you create staging slot choosing "Don't clone configuration from an existing slot". I test to choose it and it worked fine. When I choose an exist app it occured errors. Also, you could Take App Offline from this link:stackoverflow.com/questions/20792405/… The second answer.Joey Cai

2 Answers

5
votes

As you have enabled Application Insights on your Azure App Service, it has internally installed an extension which started a continuous web job and content corresponding to web job got copied to App_Data folder. The actual problem is because extension data get copied to App_Data folder where only user's data should reside instead of infrastructure data.

Now when you are selecting the option "Remove Additional Files From Destination" in visual studio, it tries to remove all contents including Application Insights data from App_Data folder. Since Application Insights web job is already running in background hence corresponding dll files are locked.

Even if you go with option of "App Offline" or "Stop web job" and successfully able to delete all contents then your deployment will succeed but this way your Application Insights will get corrupted and hence you may have to configure Application Insights again.

Suggestion:

Select skip "App_Data" folder along with option "Remove Additional Files From Destination".

It will delete all content except App_Data folder content and hence dll files corresponding to Application Insights continuous web job will be skipped.

Reference : VSTS - Azure App Service Task Documentation

Limitation

Though this solution have a limitation - If you want to remove/modify existing user defined web jobs then can't skip App_Data folder. In such case either have to perform two step deployment or have to reinstall application insight extension again.

0
votes

I found this in another SO question:

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

... adding to your publishing profile (.pubxml).

The full answer is here: https://stackoverflow.com/a/20888597/647845

UPDATE

This is not working for me. Maybe for others. Seems to ignore the setting.