Skip to content

Instantly share code, notes, and snippets.

@cheeto-bandito
Last active January 7, 2022 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheeto-bandito/4f36a7905ecfa2fc6f5c15a0b7bf78a2 to your computer and use it in GitHub Desktop.
Save cheeto-bandito/4f36a7905ecfa2fc6f5c15a0b7bf78a2 to your computer and use it in GitHub Desktop.
Unpack Sitecore Update Package
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
</ItemGroup>
</Project>
param (
$PackageName = "SC Hotfix 408137-1",
$PackageDirectory = $PSScriptRoot,
$UnpackDirectory = "$PackageDirectory\$PackageName",
$TargetsTemplatePath = "$PackageDirectory\Sitecore.Support.Template.targets"
)
Remove-Item -Path $UnpackDirectory -Force -Recurse -ErrorAction Ignore
Remove-Item -Path "$PackageDirectory\lib" -Force -Recurse -ErrorAction Ignore
Remove-Item -Path "$PackageDirectory\build" -Force -Recurse -ErrorAction Ignore
Remove-Item -Path "$PackageDirectory\src" -Force -Recurse -ErrorAction Ignore
Expand-Archive "$PackageDirectory\$PackageName.zip" -DestinationPath $UnpackDirectory -Force
Rename-Item -Path "$UnpackDirectory\$PackageName.update" -NewName "$PackageName.zip"
Expand-Archive "$UnpackDirectory\$PackageName.zip" -DestinationPath $UnpackDirectory -Force
Expand-Archive "$UnpackDirectory\package.zip" -DestinationPath $UnpackDirectory -Force
Remove-Item -Path "$UnpackDirectory\package.zip" -Force
$folders = Get-ChildItem -Path $UnpackDirectory -Exclude "properties", "readme.txt", "*.zip"
$dlls = $folders | Get-ChildItem -Filter *.dll -Recurse | Select-Object -ExpandProperty VersionInfo
New-Item -Path $PackageDirectory -Name "lib" -ItemType "directory"
$doc = New-Object System.Xml.XmlDocument
$doc.Load($TargetsTemplatePath)
$ns = $doc.DocumentElement.NamespaceURI
[System.Xml.XmlNamespaceManager]$nsmgr = $doc.NameTable
$nsmgr.AddNamespace("msb", "http://schemas.microsoft.com/developer/msbuild/2003")
$itemGroup = $doc.SelectSingleNode("//msb:Project/msb:ItemGroup", $nsmgr)
foreach ($dll in $dlls)
{
$fileName = Split-Path $dll.FileName -leaf
$assembly = $doc.CreateElement("SitecoreHotfixAssemblies", $ns)
$assembly.SetAttribute("Include", $fileName)
$name = $doc.CreateElement("Name", $ns)
$name.InnerText = $fileName
$assembly.AppendChild($name)
$version = $doc.CreateElement("Version", $ns)
$version.InnerText = $dll.FileVersion
$assembly.AppendChild($version)
$fileversion = $doc.CreateElement("FileVersion", $ns)
$fileversion.InnerText = $dll.FileVersion
$assembly.AppendChild($fileversion)
$infoversion = $doc.CreateElement("InfoVersion", $ns)
$infoversion.InnerText = $dll.ProductVersion
$assembly.AppendChild($infoversion)
$itemGroup.AppendChild($assembly)
Copy-Item -Path $dll.FileName -Destination "$PackageDirectory\lib\$fileName"
}
New-Item -Path $PackageDirectory -Name "build" -ItemType "directory"
$doc.Save("$PackageDirectory\build\Sitecore.Support.targets")
New-Item -Path $PackageDirectory -Name "src" -ItemType "directory"
Copy-Item -Path "$PackageDirectory\$PackageName\addedfiles\*" -Exclude "bin" -Recurse -Destination "$PackageDirectory\src\"
Copy-Item -Path "$PackageDirectory\$PackageName\changedfiles\*" -Exclude "bin" -Recurse -Destination "$PackageDirectory\src\"
Remove-Item -Path "$UnpackDirectory" -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment