MSBuild.Community.Tasks和Zip,设置zip文件夹结构

时间:2012-01-31 09:58:52

标签: visual-studio-2010 msbuild

我有一个MSBuild脚本,如下所示,它抓取类库Bin\Release\MyLib.dll并将其拉入C:\1.zip

当我打开zip文件时,我在父文件夹中看到MyLib.dll文件。

但我想在ZIP文件中有一个目录结构,因此该文件将被压缩为lib\MyLib.dll

我该怎么做?

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

1 个答案:

答案 0 :(得分:4)

我会:

  1. 创建“lib”文件夹
  2. 将有问题的DLL复制到“lib”文件夹
  3. 压缩“lib”文件夹,该文件夹现在包含DLL。
  4. 以下是代码:

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