© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
1 reply
_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"
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Deploy Blazor Wasm to IIS localhost
C#CC# / help
3y ago
IIS Deploy ASP NET CORE Project
C#CC# / help
4y ago
✅ how to write web.config for IIS deploy
C#CC# / help
2y ago
❔ How to deploy asp.net sites to Docker IIS?
C#CC# / help
3y ago