diff --git a/Source/MSBuild.Community.Tasks/Zip.cs b/Source/MSBuild.Community.Tasks/Zip.cs index e827aa32..b72d56cd 100644 --- a/Source/MSBuild.Community.Tasks/Zip.cs +++ b/Source/MSBuild.Community.Tasks/Zip.cs @@ -65,6 +65,17 @@ namespace MSBuild.Community.Tasks /// ZipFileName="D:\svn\repo.zip" /> /// /// ]]> + /// Create a zip file using a root directory. + /// + /// + /// + /// + /// + /// + /// ]]> /// public class Zip : Task { @@ -137,11 +148,19 @@ public Zip() /// /// The working directory. /// - /// The working directory is the base of the zip file. /// All files will be made relative from the working directory. /// public string WorkingDirectory { get; set; } + /// + /// Gets or sets the root directory for the archive. + /// + /// The root directory. + /// + /// The root directory is the base of the archive. + /// + public string RootDirectory { get; set; } + /// /// Gets or sets the password. /// @@ -263,7 +282,7 @@ private bool ZipFiles() // maybe a directory if (Directory.Exists(name)) { - var directoryEntry = zip.AddDirectory(name, directoryPathInArchive); + var directoryEntry = zip.AddDirectory(name, GetArchivePath(RootDirectory, directoryPathInArchive)); if (!Quiet) Log.LogMessage(Resources.ZipAdded, directoryEntry.FileName); @@ -279,7 +298,7 @@ private bool ZipFiles() && Path.GetFileName(directoryPathInArchive) == Path.GetFileName(name)) directoryPathInArchive = Path.GetDirectoryName(directoryPathInArchive); - var entry = zip.AddFile(name, directoryPathInArchive); + var entry = zip.AddFile(name, GetArchivePath(RootDirectory, directoryPathInArchive)); if (!Quiet) Log.LogMessage(Resources.ZipAdded, entry.FileName); } @@ -297,6 +316,15 @@ private bool ZipFiles() return true; } + private static string GetArchivePath(string rootDirectory, string directoryPathInArchive) + { + return String.IsNullOrEmpty(rootDirectory) + ? directoryPathInArchive + : String.IsNullOrEmpty(directoryPathInArchive) + ? rootDirectory + : Path.Combine(rootDirectory, directoryPathInArchive); + } + private static string GetPath(string originalPath, string rootDirectory) { var relativePath = new List(); diff --git a/readme.md b/readme.md index ed56cef9..da282fa6 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,7 @@ +> # Archived Repository 🚨 +> **This project is no longer maintained and has been archived. No further issues, PRs, or updates will be made.** +--- + #MSBuild Community Tasks The MSBuild Community Tasks Project is an open source project for MSBuild tasks.