Skip to content

Instantly share code, notes, and snippets.

@sakapon
Created October 13, 2015 08:40
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 sakapon/7e4c4ba5e9ddceb10237 to your computer and use it in GitHub Desktop.
Save sakapon/7e4c4ba5e9ddceb10237 to your computer and use it in GitHub Desktop.
BuildSample / Create ZIP (C# in PowerShell)
# source directory path
if (-not ($Args[0])) { return 100 }
# target zip file path
if (-not ($Args[1])) { return 101 }
$references = @("System.IO.Compression.FileSystem")
$source = @"
using System;
using System.IO;
using System.IO.Compression;
public static class ZipHelper
{
public static void CreateZip(string sourceDirPath, string targetZipFilePath)
{
var targetDirPath = Path.GetDirectoryName(targetZipFilePath);
Directory.CreateDirectory(targetDirPath);
File.Delete(targetZipFilePath);
ZipFile.CreateFromDirectory(sourceDirPath, targetZipFilePath);
}
}
"@
Add-Type -TypeDefinition $source -Language CSharp -ReferencedAssemblies $references
[ZipHelper]::CreateZip($Args[0], $Args[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment