0

I can zip an explicit list of folders like this:

<ItemGroup>
  <Folder Include="Foo\**\*.*"><Name>Foo</Name></Folder>
  <Folder Include="Bar\**\*.*"><Name>Bar</Name></Folder>
</ItemGroup>
<Zip
  ZipFileName="%(Folder.Name).zip"
  WorkingDirectory="%(Folder.Name)\"
  Files="@(Folder)" />

This creates two zip files Foo.zip and Bar.zip, one for each folder Foo\ and Bar\.

How can I do this for all existing folders? (Without listing each folder explicitly. When a new folder New\ is created, a zip file New.zip should be created automatically without changing the MSBuild file.)

(I'm using the Zip task from the MSBuild.Community.Tasks)

Peter
  • 3,322
  • 3
  • 27
  • 41

1 Answers1

1

I've not used the MSBuild.Community.Tasks but with the MSBuild Extension Pack 4.0.12.0 I think this will get you what you would like...change the path $(MSBuildProjectDirectory) to where you need to zip.

      <?xml version="1.0" encoding="utf-8" ?>        
        <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
             <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks" />

            <PropertyGroup>
                <BuildDependsOn>
                  $(BuildDependsOn);
                  ZipFiles;
                </BuildDependsOn>
              </PropertyGroup>

              <Target Name="ZipFiles">

                <MSBuild.ExtensionPack.FileSystem.FindUnder
                   TaskAction="FindDirectories"
                   Path="$(MSBuildProjectDirectory)\..\"
                   Recursive="false">
                  <Output ItemName="AllFoundDirectories" TaskParameter="FoundItems"/>
                </MSBuild.ExtensionPack.FileSystem.FindUnder>

                <Message Text="===== Found Directories =====" Importance="high"/>        
                <Message Text="AllFoundDirectories:%0d%0a@(AllFoundDirectories,'%0d%0a')"/>

                <MSBuild.ExtensionPack.Compression.Zip
                  TaskAction="Create"
                  CompressPath="%(AllFoundDirectories.FullPath)"
                  ZipFileName="%(AllFoundDirectories.FullPath)\%(AllFoundDirectories.Filename).zip" />

              </Target>

            </Project>
Gary Howlett
  • 1,297
  • 1
  • 14
  • 17