From 4b96ff544105657e9beeeac850452312cbb7f530 Mon Sep 17 00:00:00 2001 From: Chris Fontan Date: Tue, 24 May 2016 08:47:15 -0500 Subject: [PATCH] Fixed up commit submitted for hierarchy of zip files. --- README.md | 23 ++++++++++++++++++++++- common.tasks | 13 +++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e790ccd..d48219e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Useful MSBuild inline tasks and targets. Import the common.tasks and/or common.t Usage examples -Zip task: +Zip task (ignore hierarchy): ```xml @@ -18,6 +18,27 @@ Zip task: OverwriteExistingFile="true" /> ``` +Zip task (folders hierarchy maintained relative to InputBaseDirectory): + + + + + + + +ZipDir task (folders hierarchy maintained relative to InputBaseDirectory): + + + + SafeGitClean: diff --git a/common.tasks b/common.tasks index 9439a45..5f46d38 100644 --- a/common.tasks +++ b/common.tasks @@ -4,6 +4,7 @@ + @@ -13,11 +14,19 @@ Path.GetFullPath(f.ItemSpec)).Where(n => n.StartsWith(baseDir)); + using (var archive = new ZipArchive(new FileStream(OutputFileName, fileMode), ZipArchiveMode.Create)) { - foreach (var inputFileName in InputFileNames.Select(f => f.ItemSpec)) + foreach (var inputFileName in filesToZip) { - var archiveEntry = archive.CreateEntry(Path.GetFileName(inputFileName)); + var entryName = baseDir.Length == 0 + ? Path.GetFileName(inputFileName) + : inputFileName.Substring(baseDir.Length + 1); + + + var archiveEntry = archive.CreateEntry(entryName); using (var fs = new FileStream(inputFileName, FileMode.Open)) { using (var zipStream = archiveEntry.Open())