I have 4 azure websites each one with its own "staging" deployment slot. All of this staging slots are deployed using the same source code repository (git).
It's the same solution and each azure website compiles it's own project using the "Project" setting (azure website --> configuration tab --> application settings).
In fact almost always works well, but sometimes (10% of time) it throws me an annoying implementation error:
KuduSync.NET from: 'D:\local\Temp\a8b0a9fb-c31c-45a1-92d3-55b80315a6dc' to: 'D:\home\site\wwwroot' Error: Failed to change file that is currently being used "D:\home\site\wwwroot\Web.config" Copying file: 'Web.config' Failed exitCode=1, command="kudusync" -v 50 -f "D:\local\Temp\a8b0a9fb-c31c-45a1-92d3-55b80315a6dc" -t "D:\home\site\wwwroot" -n "D:\home\site\deployments\6c8e6d6ba36c35d7adf1c0a2f93f5397df2600d1\manifest" -p "D:\home\site\deployments\52aaaa055bb165ee2b0b7ecbb78011b252ed001a\manifest" -i ".git;.hg;.deployment;deploy.cmd" An error has occurred during web site deployment.
I understand what it means, but it have no sense for me. The staging websites are almost never used (only for test purpuses) and the "Always available" setting is set to false.
For more details, some of the staging websites throws the error and some others not.
What I do for now is wait a little (5 minutes, 10, 15...), retry the deploy and pray to the god of the bits.
Anyone knows what's the problem?
Thanks in advance.
EDIT
I've modified the deploy.cmd following the steps proposed by @beatcracker and added two lines before the KuduSync step:
del "%DEPLOYMENT_TARGET%\web.config.bak"
rename "%DEPLOYMENT_TARGET%\web.config" "%DEPLOYMENT_TARGET%\web.config.bak".
It still doesn't work. This is the error message:
The process cannot access the file because it is being used by another process.
So it's not a kudu problem. I really don't know why is my web.config locked. I've tried to rename the web.config using the Debug console (*.scm.azurewebsites.net/DebugConsole) and the same error message is repeated.
If I kill the w3wp.exe process the deployment success.
Is there any way of knowing why is my web.config locked (¡¡sometimes!!)?
** UPDATE 2 ** I thought that @beatcracker was the correct one but I'm still struggling with the problem.
I've added this two lines to my deploy.cmd
cd %DEPLOYMENT_TARGET%
for /F "tokens=3,6 delims=: " %%I IN ('%DEPLOYMENT_SOURCE%\Handle.exe -accepteula Web.config') DO %DEPLOYMENT_SOURCE%\Handle.exe -accepteula -c %%J -y -p %%I
Note that I needed to add the -accepteula argument on the DO statement and I needed to do "cd %DEPLOYMENT_TARGET%" because it didn't work if I set it in the IN statement.
And the new problem is...
Error closing handle: A
I've been Googling and I didn't find any description of an "A" error.
Any idea?