diff --git a/README.md b/README.md index e790ccd..c1e2066 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 (folders hierarchy ignored): ```xml @@ -19,6 +19,32 @@ Zip task: ``` +Zip task (folders hierarchy maintained relative to InputBaseDirectory): + +```xml + + + + + + +``` +ZipDir task (folders hierarchy maintained relative to InputBaseDirectory): + +```xml + + + +``` + SafeGitClean: ``` @@ -26,4 +52,4 @@ msbuild common.targets /p:BackupDir=C:\temp\backup /p:DeleteBackupDir=true ``` If BackupDir is not provided a directory in %TEMP% will be created -The default value for DeleteBackupDir is 'false' \ No newline at end of file +The default value for DeleteBackupDir is 'false' diff --git a/common.tasks b/common.tasks index 9439a45..47ea3f0 100644 --- a/common.tasks +++ b/common.tasks @@ -4,28 +4,40 @@ + - + - Path.GetFullPath(f.ItemSpec)).Where(n => n.StartsWith(baseDir)); + + using (var archive = new ZipArchive(new FileStream(OutputFileName, fileMode), ZipArchiveMode.Create, leaveOpen: false)) { - foreach (var inputFileName in InputFileNames.Select(f => f.ItemSpec)) + foreach (var inputFileName in filesToZip) + { + var entryName = baseDir.Length == 0 + ? Path.GetFileName(inputFileName) + : inputFileName.Substring(baseDir.Length + 1); + + Log.LogMessage(MessageImportance.High, "Zipping '" + entryName + "' from " + inputFileName); + + var archiveEntry = archive.CreateEntry(entryName); + using (var fs = new FileStream(inputFileName, FileMode.Open)) { - var archiveEntry = archive.CreateEntry(Path.GetFileName(inputFileName)); - using (var fs = new FileStream(inputFileName, FileMode.Open)) - { - using (var zipStream = archiveEntry.Open()) - { - fs.CopyTo(zipStream); - } - } + using (var zipStream = archiveEntry.Open()) + { + fs.CopyTo(zipStream); + } } + } } ]]> @@ -38,7 +50,7 @@ - + @@ -47,16 +59,16 @@