Script i used.
param (
[string]$ProjectPath = "C:\GitRepo\MyApp\MyApp.csproj",
[string]$OutputRoot = "C:\Deployment\Publish",
[string]$Configuration = "Release",
[string]$Runtime = "win-x64"
)
Prepare output directory
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
publishDir=Join−PathOutputRoot "Published_$timestamp"
zipPath="publishDir.zip"
Clean bin/obj to avoid locked files
projectRoot=Split−PathProjectPath
Remove-Item "$projectRoot\bin" -Recurse -Force -ErrorAction Ignore
Remove-Item "$projectRoot\obj" -Recurse -Force -ErrorAction Ignore
Write-Host "🔧 Step 1: Restoring NuGet packages..."
dotnet restore $ProjectPath --disable-parallel --ignore-failed-sources
Write-Host "`n🚀 Step 2: Publishing .NET 8 project to: $publishDir"
dotnet publish $ProjectPath `
-c $Configuration `
-r $Runtime `
-o $publishDir `
--self-contained false `
/p:PublishTrimmed=false
if (-not (Test-Path $publishDir)) {
Write-Error "❌ Publish folder not created. Check for build errors."
exit 1
}
Write-Host "`n📦 Step 3: Creating ZIP package: $zipPath"
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::CreateFromDirectory(publishDir,zipPath)
Write-Host "`n✅ Final ZIP ready for IIS deployment:"
Write-Host $zipPath
Please include suggested fix to resolve error.