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

在NAnt中可以使用

 1<zip>标签进行文件压缩打包,如下所示: 
 2
 3<target name="backup">
 4<zip zipfile="${backup.dir}\Src_Bak.zip">
 5<fileset basedir=".">
 6<includes name="**"></includes>
 7<excludes name="**\bin\\**"></excludes>
 8<excludes name="**\obj\\**"></excludes>
 9</fileset>
10</zip>
11</target>
12
13原以为很简单的事,在实际使用中遇到了小麻烦,含有中文路径的文件会出错。症状是可以正常打包,但在解压时会提示该文件异常,无法解压。 
14
15通过查NAnt的在线帮助( http://nant.sourceforge.net/help ),发现NAnt中的zip压缩是调用SharpZipLib(注:用C#写的开源的压缩函数库,网址 http://www.icsharpcode.net/OpenSource/SharpZipLib/ ),最新的SharpZipLib的版本是0.81.0.1407版。 
16
17然而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目录下的同名文件。 
18
19打开\src\NAnt.Zip\Tasks\ZipTask.cs文件,注释掉164行代码,如下所示: 
20
21160 // set compression level   
22161 if (ZipLevel &gt; 0) {   
23162 zOutstream.SetLevel(ZipLevel);   
24163 } else {   
25164  //zOutstream.SetMethod(ZipOutputStream.STORED); //注释掉这一行,因为新版的SharpZipLib中没有这个方法 
26
27166 // setting the method to store still compresses the files   
28167 // setting the level to 0 fixes this   
29168 zOutstream.SetLevel(ZipLevel);   
30169 } 
31
32重新编译NAnt,用编译生成的NAnt.ZipTasks.dll以及下载的最新SharpZipLib库文件覆盖旧的NAnt同名文件即可。</zip>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus