How to use MSBuild extension's Zip task?

前端 未结 2 1810
庸人自扰
庸人自扰 2021-02-04 00:13

I decided to use MSBuild Extension\'s Zip task to compress some of my source code at every build.

However, this not works:



        
相关标签:
2条回答
  • 2021-02-04 00:55

    Here's an alternative to MSBuild Community Tasks. If you're using .net 4.5.1, you can embed the System.IO.Compression functions in a UsingTask. This example uses ZipFile.CreateFromDirectory.

    <Target Name="Build">
      <ZipDir
        ZipFileName="MyZipFileName.zip"
        DirectoryName="MyDirectory"
      />
    </Target>
    
    <UsingTask TaskName="ZipDir" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
      <ParameterGroup>
        <ZipFileName ParameterType="System.String" Required="true" />
        <DirectoryName ParameterType="System.String" Required="true" />
      </ParameterGroup>
      <Task>
        <Reference Include="System.IO.Compression.FileSystem" />
        <Using Namespace="System.IO.Compression" />
        <Code Type="Fragment" Language="cs"><![CDATA[
          try
          {
            Log.LogMessage(string.Format("Zipping Directory {0} to {1}", DirectoryName, ZipFileName));
            ZipFile.CreateFromDirectory( DirectoryName, ZipFileName );
            return true;
          }
          catch(Exception ex)
          {
            Log.LogErrorFromException(ex);
            return false;
          }
        ]]></Code>
      </Task>
    </UsingTask>
    
    0 讨论(0)
  • 2021-02-04 01:05

    Example for MSBuild Community Tasks:

    <Import Project="lib\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
    
    <Target Name="Zip">
            <CreateItem Include="YourSourceFolder\*.*" >
                    <Output ItemName="ZipFiles" TaskParameter="Include"/>
            </CreateItem>
            <Zip ZipFileName="YourZipFile.zip" WorkingDirectory="YourSourceFolder" Files="@(ZipFiles)" />
    </Target>
    

    If you need more examples, here is a complete working MSBuild file from one of my projects.

    0 讨论(0)
提交回复
热议问题