Tomas
Tomas

Reputation: 18127

MSBuild.Community.Tasks and Zip, set zip folder structure

I have an MSBuild script as shown below, which grabs the class library Bin\Release\MyLib.dll and zips it into C:\1.zip.

When I open the zip file I see MyLib.dll file in the parent folder.

But I would like to have a directory structure in the ZIP file, so the file would be zipped as lib\MyLib.dll

How can I do that?

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
    <Target Name="AfterBuild">
        <PropertyGroup>      
            <ReleasePath>bin\Release\</ReleasePath>
        </PropertyGroup>
    <ItemGroup>      
        <ReleaseApplicationFiles
            Include="$(ReleasePath)\**\*.*"
            Exclude="$(ReleasePath)\*vshost.exe*;$(ReleasePath)\*.pdb*" />
    </ItemGroup>
    <Zip Files="@(ReleaseApplicationFiles)" 
      WorkingDirectory="$(ReleasePath)"
      ZipFileName="c:\1.zip"
      ZipLevel="9" />
    </Target>

Upvotes: 2

Views: 4149

Answers (1)

scrat.squirrel
scrat.squirrel

Reputation: 3836

I would:

  1. create the "lib" folder
  2. copy the DLL in question into the "lib" folder
  3. zip up the "lib" folder which now contains the DLL.

Here's the code:

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Target Name="AfterBuild">
  <PropertyGroup>      
    <ReleasePath>bin\Release\</ReleasePath>
    <Zipup>c:\archive\bin</Zipup>
  </PropertyGroup>

  <ItemGroup>      
    <ReleaseApplicationFiles Include="$(ReleasePath)\**\*.*" Exclude="$(ReleasePath)\*vshost.exe*;$(ReleasePath)\*.pdb*" />
  </ItemGroup>

  <Exec Command="mkdir $(Zipup)" IgnoreExitCode="False"/>
  <Copy DestinationFolder="$(Zipup)" OverwriteReadOnlyFiles="True" SkipUnchangedFiles="False" SourceFiles="@(ReleaseApplicationFiles)" />

  <Zip Files="$(Zipup)" 
    WorkingDirectory="$(ReleasePath)"
    ZipFileName="c:\1.zip"
    ZipLevel="9" />

</Target>

Upvotes: 4

Related Questions