Reputation: 6373
When I try to run this command from commandline to deploy asp.net core website:
"C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe" -allowUntrusted -verb:sync -sourc
e:contentPath="%USERPROFILE%\ProjectFolder\bin\release\netcoreapp1.1\publish" -dest:contentPath="sitename",ComputerNa
me="https://siteurl.com:8172/msdeploy.axd?site=sitename",UserName='myusername',Password='mypassword',AuthType='Basic' -enableRule:AppOffline -retryAttempts:20
Get this error:
Error Code: ERROR_FILE_IN_USE
When I stop website on web server, then deployment succeeds:
I was expecting -enableRule:AppOffline
should force website offline. But it still keeps the lock on website dll.
How we can force webdeploy to overwrite files?
Upvotes: 6
Views: 3165
Reputation: 11
Try increasing -retryInterval and/or -retryAttempts parameters:
Upvotes: 0
Reputation: 25069
Wow. This issue was a bear for me.
I could not get -enableRule:AppOffline
on my actual deployment command. Nor could I get this to work in my pubxml file:
<PropertyGroup>
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
</PropertyGroup>
(I'm using IIS v10)
This Microsoft blog post indicates that either will work, but no dice for me!
Anyway, these 2 references helped me a lot:
The real trick was in the second reference, the tile says "before Publishing". So you need to actually run msdeploy.exe
separately before your main deploy.
Here is the PowerShell code I used:
# Deploy app_offline.htm
$IisApp = Get-IisAppName
$AppOfflineFilePath = "`"C:\path with spaces\app_offline.htm`""
Log-Begin "Deploy app_offline.htm"
& $MsDeployPath -verb:sync -source:contentPath=$AppOfflineFilePath -dest:contentPath=$IisApp/app_offline.htm,ComputerName=$ServerName,UserName=$UserName,Password=$Password,IncludeAcls="False"
Log-End "Deploy app_offline.htm" $LastExitCode
Write-Host "Sleeping for 4 seconds to give the app_offline.htm a chance to take effect."
Write-Host "If you get a locked DLL error, just try the deployment again!"
Start-Sleep -Seconds 4
# Within the ZIP file is a MS Web Deploy Package ZIP, a cmd (to run the deploy), and some other files.
$DeployCommandFilePath = Get-ChildItem $pwd *.deploy.cmd -Recurse | Where-Object {$_.FullName.length -lt 260} | Select-Object -First 1 | Resolve-Path -Relative
Log-Begin "deploy.cmd"
& $DeployCommandFilePath /Y /M:$ServerName /U:$UserName /P:$Password
Log-End "deploy.cmd" $LastExitCode
Note that I added a short sleep to allow the app_offline.htm file a chance to take effect. It is not immediate.
I have IIS set up to automatically delete the app_offline.htm file on a deploy, so I did not need this, but here is the code if you need it:
# Delete app_offline.htm
Log-Begin "Delete app_offline.htm"
& $MsDeployPath -verb:delete -dest:contentPath=$IisApp/app_offline.htm,ComputerName=$ServerName,UserName=$UserName,Password=$Password,IncludeAcls="False"
Log-End "Delete app_offline.htm" $LastExitCode
Upvotes: 0