zoukankan      html  css  js  c++  java
  • 如何增加NAnt 0.84中的zip压缩对中文路径支持

    在NAnt中可以使用<zip>标签进行文件压缩打包,如下所示:

        <target name="backup">
            <zip zipfile="${backup.dir}\Src_Bak.zip">
                <fileset basedir=".">
                    <includes name="**" />
                    <excludes name="**\bin\**" />
                    <excludes name="**\obj\**" />
                </fileset>
            </zip>
        </target>

    原以为很简单的事,在实际使用中遇到了小麻烦,含有中文路径的文件会出错。症状是可以正常打包,但在解压时会提示该文件异常,无法解压。

    通过查NAnt的在线帮助(http://nant.sourceforge.net/help),发现NAnt中的zip压缩是调用SharpZipLib(注:用C#写的开源的压缩函数库,网址http://www.icsharpcode.net/OpenSource/SharpZipLib/),最新的SharpZipLib的版本是0.81.0.1407版。

    然而NAnt 0.84版中采用的是SharpZipLib 0.5.0.0版的!!估计问题可能就出在这儿。从SourceForge下载源文件http://optusnet.dl.sourceforge.net/sourceforge/nant/nant-0.84.zip并解压,从081SharpZipLib.zip处下载SharpZipLib 0.81.0.1407版,将ICSharpCode.SharpZipLib.dll替换掉NAnt中lib目录下的同名文件。

    打开\src\NAnt.Zip\Tasks\ZipTask.cs文件,注释掉164行代码,如下所示:

    160         // set compression level
    161        if (ZipLevel > 0) {
    162                 zOutstream.SetLevel(ZipLevel);
    163          } else {
    164              //zOutstream.SetMethod(ZipOutputStream.STORED); //注释掉这一行,因为新版的SharpZipLib中没有这个方法

    166              // setting the method to store still compresses the files
    167              // setting the level to 0 fixes this
    168              zOutstream.SetLevel(ZipLevel);
    169          }

    重新编译NAnt,用编译生成的NAnt.ZipTasks.dll以及下载的最新SharpZipLib库文件覆盖旧的NAnt同名文件即可

  • 相关阅读:
    C#设计模式-单例模式
    MVC图片上传并显示缩略图
    asp.net MVC发布iis无法加载css,js和图片
    Silverlight中获取控件中子控件
    Lambda加自定义比较器实现两个列表的合并
    MVC文件上传
    pt-osc测试
    MySQL DDL方案测试及选型.
    gh-ost测试
    gh-ost原理
  • 原文地址:https://www.cnblogs.com/rrooyy/p/55634.html
Copyright © 2011-2022 走看看