Publish to temp dir to avoid recursive copies

This commit is contained in:
2026-02-02 17:06:16 +01:00
parent e365002373
commit 8c0aebd54f

View File

@@ -6,7 +6,7 @@ $RemoteDir = "/httpdocs/picknplay"
$ProjectPath = "..\\GameList.csproj"
$Configuration = "Release"
$Runtime = "win-x64"
$PublishDir = "..\\artifacts\\publish"
$PublishDir = "$env:TEMP\\GameList-publish"
$SelfContained = $false
$WinScpPath = "C:\\Users\\frank\\AppData\\Local\\Programs\\WinSCP\\WinSCP.com"
$RecycleAppPool = $true
@@ -50,11 +50,8 @@ Assert-Tool $WinScpPath
function Read-PlainOrPrompt([string]$Value, [string]$Prompt, [bool]$Secure = $false) {
if ($Value) { return $Value }
if ($Secure) {
$secure = Read-Host -Prompt $Prompt -AsSecureString
if (-not ($secure -is [System.Security.SecureString])) {
$secure = ConvertTo-SecureString -String ([string]$secure) -AsPlainText -Force
}
$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
$pwd = Read-Host -Prompt $Prompt -AsSecureString
$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd)
try { return [Runtime.InteropServices.Marshal]::PtrToStringUni($ptr) }
finally {
if ($ptr -ne [IntPtr]::Zero) { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr) }
@@ -67,6 +64,7 @@ $FtpPassword = Read-PlainOrPrompt $FtpPassword "FTP password" $true
$WinRmCredentialPass = Read-PlainOrPrompt $WinRmCredentialPass "WinRM password" $true
Write-Host "1) Publishing..." -ForegroundColor Cyan
if (Test-Path $PublishDir) { Remove-Item $PublishDir -Recurse -Force -ErrorAction SilentlyContinue }
New-Item -ItemType Directory -Force -Path $PublishDir | Out-Null
$publishArgs = @("publish", $ProjectPath, "-c", $Configuration, "-r", $Runtime, "-o", $PublishDir)
if (-not $SelfContained) { $publishArgs += "--self-contained=false" }
@@ -88,11 +86,11 @@ if ($RecycleAppPool) {
try {
Invoke-Command @invokeParams
} catch {
Write-Warning "WinRM stop failed: $($_.Exception.Message)`nIf not on domain/Kerberos, enable HTTPS WinRM or add TrustedHosts (winrm set winrm/config/client '@{TrustedHosts=\"\"\"$WinRmComputer\"\"\"}'), or set `$RecycleAppPool = $false`."
Write-Warning "WinRM stop failed: $($_.Exception.Message)."
}
}
Write-Host "2) Syncing via WinSCP (FTP mirror with delete)..." -ForegroundColor Cyan
Write-Host "3) Syncing via WinSCP (FTP mirror with delete)..." -ForegroundColor Cyan
$tempScript = New-TemporaryFile
@"
option batch continue
@@ -123,7 +121,7 @@ if ($RecycleAppPool) {
try {
Invoke-Command @invokeParams
} catch {
Write-Warning "WinRM start failed: $($_.Exception.Message)`nIf not on domain/Kerberos, enable HTTPS WinRM or add TrustedHosts, or set `$RecycleAppPool = $false`."
Write-Warning "WinRM start failed: $($_.Exception.Message)."
}
}