用NAnt编译带有资源文件(*.resx,*.bmp,*.gif等)的C#项目


情况一:如何编译支持多语言切换的项目

    <!--
    转换资源文件的格式(编译资源文件的必要步骤)
    -->
    <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>

posted on 2004-12-09 15:59  良村  阅读(1719)  评论(1编辑  收藏  举报

导航