Language
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Creates a .zip archive from the contents of a directory.
Note
The ZipDirectory task is available in MSBuild 15.8 and above only.
Parameters
The following table describes the parameters of the ZipDirectory task.
| Parameter | Description |
|---|---|
CompressionLevel |
Optional String parameter.Sets the compression level for the archive. Available in MSBuild 18.0 and later. See Compression level. |
DestinationFile |
Required ITaskItem parameter The full path to the .zip file to create. |
Overwrite |
Optional Boolean parameter.If true, the destination file will be overwritten if it exists. Defaults to false. |
SourceDirectory |
Required ITaskItem parameter. Specifies the directory to create a .zip archive from. |
Compression level
The CompressionLevel parameter accepts the following case-insensitive values:
Optimal: Balances compression speed and archive size.Fastest: Favors speed over archive size.NoCompression: Stores files without compression.SmallestSize: Favors archive size over speed. This value is supported only when MSBuild runs on .NET, not .NET Framework.
If you omit CompressionLevel, the task uses the default compression level. If you specify an unsupported value, the task logs a warning and uses the default compression level. For example, SmallestSize causes a warning and uses the default compression level when MSBuild runs on .NET Framework. For more information about these values, see CompressionLevel.
Remarks
In addition to the parameters listed above, this task inherits parameters from the TaskExtension class, which itself inherits from the Task class. For a list of these additional parameters and their descriptions, see TaskExtension base class.
Example
The following example, when imported as a .targets file, creates a .zip archive from the output directory after a build. A project that defines $(OutputPath) and imports this file produces an archive named output.zip. The example requires MSBuild 18.0 or later.
<Project>
<Target Name="ZipOutputPath" AfterTargets="Build">
<ZipDirectory
SourceDirectory="$(OutputPath)"
DestinationFile="$(MSBuildProjectDirectory)\output.zip"
CompressionLevel="Fastest" />
</Target>
</Project>