Skip to content

Instantly share code, notes, and snippets.

@scottcowan
Created February 8, 2017 14:17
Show Gist options
  • Save scottcowan/181585a2c54ff71cbbe576558eb87e9f to your computer and use it in GitHub Desktop.
Save scottcowan/181585a2c54ff71cbbe576558eb87e9f to your computer and use it in GitHub Desktop.
unzipping Azure Cloud service
function ZipFiles( $zipfilename, $sourcedir )
{
Add-Type -Assembly System.IO.Compression.FileSystem
Add-Type -Assembly System.IO.Compression
$archive = [System.IO.Compression.ZipFile]::Open($zipfilename, [System.IO.Compression.ZipArchiveMode]::Create);
try
{
$files = [System.IO.Directory]::GetFiles($sourceDir, "*.*", [System.IO.SearchOption]::AllDirectories)
foreach ($filename in $files)
{
$relativePath = $filename.Substring($sourcedir.Length + 1).Replace("\", "/");
echo "Creating zip entry for $relativePath"
$entry = $archive.CreateEntry($relativePath, [System.IO.Compression.CompressionLevel]::Optimal);
$destination = $entry.Open();
try
{
try
{
$source = [System.IO.File]::OpenRead($filename);
$source.CopyTo($destination);
}
finally
{
$source.Dispose();
}
}
finally
{
$destination.Dispose();
}
}
}
finally
{
$archive.Dispose();
}
}
function UnzipFiles( $zipfilename, $dest )
{
Add-Type -Assembly System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfilename, $dest)
}
$cspkg = Get-ChildItem *.cspkg
$cssx = Get-ChildItem ((Get-Item -Path ".\" -Verbose).FullName + "\cspkg.temp\*.cssx")
$csdx = Get-ChildItem ((Get-Item -Path ".\" -Verbose).FullName + "\cspkg.temp\*.csdx")
rm -force $cssx.FullName
ZipFiles $cssx.FullName ((Get-Item -Path ".\" -Verbose).FullName + "\cssx.temp")
rm -force $csdx.FullName
ZipFiles $csdx.FullName ((Get-Item -Path ".\" -Verbose).FullName + "\csdx.temp")
rm -force $cspkg.FullName
ZipFiles $cspkg.FullName ((Get-Item -Path ".\" -Verbose).FullName + "\cspkg.temp")
function UnzipFiles( $zipfilename, $dest )
{
Add-Type -Assembly System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfilename, $dest)
}
$cspkg = Get-ChildItem *.cspkg
rm -Recurse -ErrorAction SilentlyContinue "cspkg.temp"
md -Force "cspkg.temp"
UnzipFiles ($cspkg.FullName) ((Get-Item -Path ".\" -Verbose).FullName + "\cspkg.temp")
$cssx = Get-ChildItem ((Get-Item -Path ".\" -Verbose).FullName + "\cspkg.temp\*.cssx")
UnzipFiles ($cssx.FullName) ((Get-Item -Path ".\" -Verbose).FullName + "\cssx.temp")
$csdx = Get-ChildItem ((Get-Item -Path ".\" -Verbose).FullName + "\cspkg.temp\*.csdx")
UnzipFiles ($csdx.FullName) ((Get-Item -Path ".\" -Verbose).FullName + "\csdx.temp")
@scottcowan
Copy link
Author

the packaging doesn't work since you need to sign it, I haven't found a good solution for this and will probably use FAKE to build multiple packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment