情況一:如何編譯支援多語言切換的項目
<!--
轉換資源檔的格式(編譯資源檔的必要步驟)
-->
<resgen input="ResourceText.resx" output="${nant.project.name}.ResourceText.resources" todir="${build.dir}\bin" />
<resgen input="ResourceText.zh-CHS.resx" output="${nant.project.name}.ResourceText.zh-CHS.resources" todir="${build.dir}\bin\zh-CHS" />
<resgen input="ResourceText.en-US.resx" output="${nant.project.name}.ResourceText.en-US.resources" todir="${build.dir}\bin\en-US" />
<!--
編譯字串資源檔(簡體中文)
-->
<al output="${build.dir}\bin\zh-CHS\${nant.project.name}.resources.dll" target="lib" culture="zh-CHS">
<sources basedir="${build.dir}\bin\zh-CHS">
<includes name="${nant.project.name}.ResourceText.zh-CHS.resources" />
</sources>
</al>
<!--
編譯字串資源檔(美國英語)
-->
<al output="${build.dir}\bin\en-US\${nant.project.name}.resources.dll" target="lib" culture="en-US">
<sources basedir="${build.dir}\bin\en-US">
<includes name="${nant.project.name}.ResourceText.en-US.resources" />
</sources>
</al>
<!--
編譯${nant.project.name}主專案
-->
<csc
warnaserror="true"
debug="${build.debug}"
doc="${build.dir}\bin\${nant.project.name}.xml"
output="${build.dir}\bin\${nant.project.name}.exe"
target="winexe" win32icon="App.ico">
<sources failonempty="true">
<includes name="**\*.cs" />
<includes name="..\CommonAssemblyInfo.cs" />
</sources>
<resources basedir="${build.dir}\bin">
<includes name="${nant.project.name}.ResourceText.resources" />
</resources>
</csc>
情況二:如何編譯帶有圖片資源的項目
當資源檔名的命名方式剛好與那些VS.NET自動產生的資源檔名相同時,你不需要使用(也不應該使用) <resgen>標籤。
你應該使用<resources>標籤,由編譯任務在編譯時間執行對資源檔的編譯。
下面是一個範例:
<target name="build">
<echo message="編譯${nant.project.name}項目" />
<csc
warnaserror="true"
debug="${build.debug}"
doc="${build.dir}\bin\${nant.project.name}.xml"
output="${build.dir}\bin\${nant.project.name}.dll"
target="library">
<sources failonempty="true">
<includes name="**\*.cs" />
<includes name="..\CommonAssemblyInfo.cs" />
</sources>
<resources basedir="." prefix="${nant.project.name}" dynamicprefix="true">
<includes name="Arrows\*.gif" />
<includes name="CheckBoxes\*.bmp" />
<includes name="RadioButtons\*.gif" />
</resources>
</csc>
</target>