Zip Class

MSBuild Extension Pack

Zip Class MSBuild Extension Pack Help 4.0.12.0
Valid TaskActions are:

AddFiles (Required: ZipFileName, CompressFiles or Path Optional: CompressionLevel, MaxOutputSegmentSize, Password; RemoveRoot, UseZip64WhenSaving) Existing files will be updated

Create (Required: ZipFileName, CompressFiles or Path Optional: CompressionLevel, MaxOutputSegmentSize, Password; RemoveRoot, UseZip64WhenSaving, PreserveAttributes)

Extract (Required: ZipFileName, ExtractPath Optional: Password)

Remote Execution Support: NA

This task uses http://dotnetzip.codeplex.com v1.9.1.8 for compression.

Inheritance Hierarchy

SystemObject  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPackBaseTask
      MSBuild.ExtensionPack.CompressionZip

Namespace: MSBuild.ExtensionPack.Compression
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 4.0.0.0

The Zip type exposes the following members.

Constructors

  NameDescription
Public methodZip
Top
Properties

  NameDescription
Public propertyCompressFiles
Sets the files to Compress
Public propertyCompressionLevel
Sets the CompressionLevel to use. Default is Default, also supports BestSpeed and BestCompression
Public propertyCompressPath
Sets the Path to Zip.
Public propertyExtractPath
Path to extract the zip file to
Public propertyMaxOutputSegmentSize
Sets the maximum output segment size, which typically results in a split archive (an archive split into multiple files). This value is not required and if not set or set to 0 the resulting archive will not be split. For more details see the DotNetZip documentation.
Public propertyPassword
Sets the Password to be used
Public propertyPreserveAttributes
This is only applicable when the TaskAction is Create or AddFiles. Specifies whether file (folder) attributes like Hidden or Read-only should be left intact during adding to the archive. The default is true.
Public propertyRemoveRoot
Sets the root to remove from the zip path. Note that this should be part of the file to compress path, not the target path of the ZipFileName
Public propertyUseZip64WhenSaving
Sets the UseZip64WhenSaving output of the DotNetZip library. For more details see the DotNetZip documentation.
Public propertyZipFileName
Sets the name of the Zip File
Top
Examples

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
    <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
  </PropertyGroup>
  <Import Project="$(TPath)"/>
  <Target Name="Default" DependsOnTargets="Sample1;Sample2"/>
  <Target Name="Sample1">
    <ItemGroup>
      <!-- Set the collection of files to Zip-->
      <FilesToZip Include="C:\Patches\**\*"/>
    </ItemGroup>
    <!-- Create a zip file based on the FilesToZip collection -->
    <MSBuild.ExtensionPack.Compression.Zip TaskAction="Create" CompressFiles="@(FilesToZip)" ZipFileName="C:\newZipByFile.zip"/>
    <MSBuild.ExtensionPack.Compression.Zip TaskAction="Create" Password="apassword" CompressionLevel="BestCompression" RemoveRoot="C:\Patches" CompressFiles="@(FilesToZip)" ZipFileName="C:\newZipByFileBestCompression.zip"/>
    <!-- Create a zip file based on a Path -->
    <MSBuild.ExtensionPack.Compression.Zip TaskAction="Create" CompressPath="C:\Patches" ZipFileName="C:\newZipByPath.zip"/>
    <!-- Extract a zip file-->
    <MSBuild.ExtensionPack.Compression.Zip TaskAction="Extract" ExtractPath="C:\aaa11\1" ZipFileName="C:\newZipByFile.zip"/>
    <MSBuild.ExtensionPack.Compression.Zip TaskAction="Extract" ExtractPath="C:\aaa11\2" ZipFileName="C:\newZipByPath.zip"/>
    <MSBuild.ExtensionPack.Compression.Zip TaskAction="Extract" Password="apassword"  ExtractPath="C:\aaa11\3" ZipFileName="C:\newZipByFileBestCompression.zip"/>
  </Target>
  <Target Name="Sample2">
    <PropertyGroup>
      <SourceDirectory>MotorData\</SourceDirectory>
    </PropertyGroup>
    <ItemGroup>
      <Files Include="$(SourceDirectory)*" Exclude="$(SourceDirectory).XYZ\**\*">
        <Group>Common</Group>
      </Files>
      <Files Include="$(SourceDirectory)Cars\*" Exclude="$(SourceDirectory)Cars\.XYZ\**\*">
        <Group>Cars</Group>
      </Files>
      <Files Include="$(SourceDirectory)Trucks\*" Exclude="$(SourceDirectory)Trucks\.XYZ\**\*">
        <Group>Trucks</Group>
      </Files>
    </ItemGroup>
    <!-- Create the output folder -->
    <ItemGroup>
      <OutputDirectory Include="output\"/>
    </ItemGroup>
    <MakeDir Directories="@(OutputDirectory)"/>
    <PropertyGroup>
      <WorkingDir>%(OutputDirectory.Fullpath)</WorkingDir>
    </PropertyGroup>
    <!-- Zip files based on the group they belong to -->
    <MSBuild.ExtensionPack.Compression.Zip TaskAction="Create" CompressFiles="@(Files)" ZipFileName="$(WorkingDir)%(Files.Group).zip"/>
  </Target>
</Project>
See Also

Reference