DNZip Class

MSBuild Extension Pack

DNZip Class MSBuild Extension Pack Help 4.0.12.0

NOTE: This task is for backwards compatibility only. You should use the Zip task rather

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)

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.CompressionDNZip

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

The DNZip type exposes the following members.

Constructors

  NameDescription
Public methodDNZip
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 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.DNZip TaskAction="Create" CompressFiles="@(FilesToZip)" ZipFileName="C:\newZipByFile.zip"/>
    <MSBuild.ExtensionPack.Compression.DNZip 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.DNZip TaskAction="Create" CompressPath="C:\Patches" ZipFileName="C:\newZipByPath.zip"/>
    <MSBuild.ExtensionPack.Compression.DNZip TaskAction="Create" CompressPath="C:\Patches" ZipFileName="C:\newZipByPath.zip" MaxOutputSegmentSize="734003200" UseZip64WhenSaving="AsNecessary"/>
    <!-- Extract a zip file-->
    <MSBuild.ExtensionPack.Compression.DNZip TaskAction="Extract" ExtractPath="C:\aaa11\1" ZipFileName="C:\newZipByFile.zip"/>
    <MSBuild.ExtensionPack.Compression.DNZip TaskAction="Extract" ExtractPath="C:\aaa11\2" ZipFileName="C:\newZipByPath.zip"/>
    <MSBuild.ExtensionPack.Compression.DNZip 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.DNZip TaskAction="Create" CompressFiles="@(Files)" ZipFileName="$(WorkingDir)%(Files.Group).zip"/>
  </Target>
</Project>
See Also

Reference