Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions scripts/Clear-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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"

Expand All @@ -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
Expand Down