Reputation: 2525
I have a folder with a large number of *.xml files.
I need all those files to be zipped each in a separate zip file.
Example: - file1.xml - file2.xml - file3.xml
After msbuild: - file1.zip - file2.zip - file3.zip
Note that I do not need to zip all the files within one ZIP, and the number of .xml files within the folder will vary everytime.
Is there anyway to do this with an automated msbuild task?
Thanks in advance.
Upvotes: 2
Views: 1603
Reputation: 14164
Use the Zip task from MSBuild Extension Pack. Then your MSBuild target can be something like:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="ZipFiles">
<UsingTask TaskName="MSBuild.ExtensionPack.Compression.Zip"
AssemblyFile="..\MSBuildExtensionPack\Releases\4.0.4.0\MSBuild.ExtensionPack.dll" />
<Target Name="ZipFiles">
<ItemGroup>
<FilesToZip Include="xmls\**\*.xml"/>
</ItemGroup>
<Message Text="Zipping '%(FilesToZip.Identity)'" Importance="high" />
<MSBuild.ExtensionPack.Compression.Zip TaskAction="Create"
CompressFiles="%(FilesToZip.FullPath)"
ZipFileName="%(FilesToZip.Filename).zip"
RemoveRoot="%(FilesToZip.RootDir)%(FilesToZip.Directory)" />
</Target>
</Project>
Upvotes: 3