diff --git a/scripts/Clear-Package.ps1 b/scripts/Clear-Package.ps1 index 67411e0..e97be23 100644 --- a/scripts/Clear-Package.ps1 +++ b/scripts/Clear-Package.ps1 @@ -7,10 +7,9 @@ param( [string]$Path ) +# Create temp folder $tempPath = Join-Path $PSScriptRoot "\temp" - -# unzip so we can update parameters and archive files -Expand-Archive -Path $Path -DestinationPath $tempPath -Force; +New-Item -ItemType directory -Force -Path $tempPath | Out-Null function Remove-Elements($XmlPath, $XPath) { @@ -27,12 +26,6 @@ function Remove-Elements($XmlPath, $XPath) $xml.Save($XmlPath) } -# remove sql parameter elements from parameters -Remove-Elements -XmlPath (Join-Path $tempPath "parameters.xml") -XPath ".//parameter[contains(@tags, 'SQLConnectionString')]" - -# remove dacfx elements from archive -Remove-Elements -XmlPath (Join-Path $tempPath "archive.xml") -XPath ".//dbDacFx" - Add-Type -AssemblyName "System.IO.Compression" Add-Type -AssemblyName "System.IO.Compression.FileSystem" @@ -42,10 +35,20 @@ try $zip = New-Object IO.Compression.ZipArchive($stream, [IO.Compression.ZipArchiveMode]::Update) # delete dacpac, old parameters and archive files - ($zip.Entries | Where-Object { $_.FullName -like "*.dacpac" -or $_.FullName -eq "parameters.xml" -or $_.FullName -eq "archive.xml" }) | Foreach-Object { + ($zip.Entries | Where-Object { $_.FullName -like "*.dacpac" -or $_.FullName -eq "parameters.xml" -or $_.FullName -eq "archive.xml" }) | Foreach-Object { + if ($_.FullName -like "*.xml") { + # extract the xml files before deleting them + [System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, (Join-Path $tempPath $_.FullName), $true) + } $_.Delete() } + # remove sql parameter elements from parameters + Remove-Elements -XmlPath (Join-Path $tempPath "parameters.xml") -XPath ".//parameter[contains(@tags, 'SQLConnectionString')]" + + # remove dacfx elements from archive + Remove-Elements -XmlPath (Join-Path $tempPath "archive.xml") -XPath ".//dbDacFx" + # update zip with new parameters and archive files [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, (Join-Path $tempPath "\parameters.xml"), "parameters.xml", "Optimal") | Out-Null [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, (Join-Path $tempPath "\archive.xml"), "archive.xml", "Optimal") | Out-Null