C
C#2y ago
_moare

❔ Deploy app to IIS

does anyone how i can make this deploy script for a .net application more reliable? When i run this script i often get a "Access to the path 'xxx' is denied" on the remove-item step, cause IIS still uses it. what would be the cleanest way to set it offline? Stopping the appPool would work, problem is i can't set a custom error page for that case.
Write-Host "Take app offline"
if(!(Test-Path "$($targetFolder)\app_offline.htm")) {
New-Item -Path "$($targetFolder)" -Name "app_offline.htm" -ItemType "file"
}

Write-Host "Delete..."
Start-Sleep -Seconds 5
Get-ChildItem -Path "$($targetFolder)" -Exclude app_offline.htm -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Stop

Start-Sleep -Seconds 1
Write-Host "Copy new files"
Expand-Archive -Path $sourceArchive -DestinationPath $targetFolder

Start-Sleep -Seconds 1
Write-Host "Take app online"
Remove-Item -Path "$($targetFolder)\app_offline.htm"
Write-Host "Take app offline"
if(!(Test-Path "$($targetFolder)\app_offline.htm")) {
New-Item -Path "$($targetFolder)" -Name "app_offline.htm" -ItemType "file"
}

Write-Host "Delete..."
Start-Sleep -Seconds 5
Get-ChildItem -Path "$($targetFolder)" -Exclude app_offline.htm -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Stop

Start-Sleep -Seconds 1
Write-Host "Copy new files"
Expand-Archive -Path $sourceArchive -DestinationPath $targetFolder

Start-Sleep -Seconds 1
Write-Host "Take app online"
Remove-Item -Path "$($targetFolder)\app_offline.htm"
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server