Welcome

首页 / 软件开发 / .NET编程技术 / 用NAnt编译带有资源文件(*.resx,*.bmp,*.gif等)的C#项目

用NAnt编译带有资源文件(*.resx,*.bmp,*.gif等)的C#项目2011-01-19简单生活情况一:如何编译支持多语言切换的项目

<!--转换资源文件的格式(编译资源文件的必要步骤)--><resgen input="ResourceText.resx" output="${nant.project.name}.ResourceText.resources" todir="${build.dir}in" /><resgen input="ResourceText.zh-CHS.resx" output="${nant.project.name}.ResourceText.zh-CHS.resources" todir="${build.dir}inzh-CHS" /><resgen input="ResourceText.en-US.resx" output="${nant.project.name}.ResourceText.en-US.resources" todir="${build.dir}inen-US" /><!--编译字符串资源文件(简体中文)--><al output="${build.dir}inzh-CHS${nant.project.name}.resources.dll" target="lib" culture="zh-CHS"><sources basedir="${build.dir}inzh-CHS"><includes name="${nant.project.name}.ResourceText.zh-CHS.resources" /></sources></al><!--编译字符串资源文件(美国英语)--><al output="${build.dir}inen-US${nant.project.name}.resources.dll" target="lib" culture="en-US"><sources basedir="${build.dir}inen-US"><includes name="${nant.project.name}.ResourceText.en-US.resources" /></sources></al><!--编译${nant.project.name}主项目--><cscwarnaserror="true"debug="${build.debug}"doc="${build.dir}in${nant.project.name}.xml"output="${build.dir}in${nant.project.name}.exe"target="winexe" win32icon="App.ico"><sources failonempty="true"><includes name="***.cs" /><includes name="..CommonAssemblyInfo.cs" /></sources><resources basedir="${build.dir}in"><includes name="${nant.project.name}.ResourceText.resources" /></resources></csc>
情况二:如何编译带有图片资源的项目

当资源文件名的命名方式刚好与那些VS.NET自动生成的资源文件名相同时,你不需要使用(也不应该使用) <resgen>标签。

你应该使用<resources>标签,由编译任务在编译时执行对资源文件的编译。

下面是一个范例:

<target name="build"><echo message="编译${nant.project.name}项目" /><cscwarnaserror="true"debug="${build.debug}"doc="${build.dir}in${nant.project.name}.xml"output="${build.dir}in${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>