如何增加NAnt 0.84中的zip壓縮對中文路徑支援

來源:互聯網
上載者:User

在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同名檔案即可

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.