Created
October 13, 2015 08:40
-
-
Save sakapon/7e4c4ba5e9ddceb10237 to your computer and use it in GitHub Desktop.
BuildSample / Create ZIP (C# in PowerShell)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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