您的位置:首页 > 其它

如何增加NAnt 0.84中的zip压缩对中文路径支持

2004-10-22 20:52 337 查看
在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同名文件即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: