Embedding Strongly Typed Resources using Nant

I have blogged about this previously but thought I should offer up a more complete explanation as I was asked about this recently.
 
The following nant target will generate your .resources file for you prior to building the binary and then embed it. Two things are worthy of note here:
  1. resgen.exe will generate a .resources file as well as a .cs file.
  2. The csc task embeds the resources file (in the resources element) and the .cs file (generated as the second of the two results of the exec task) is included in the sources element.
 
<property name="resgen.exe" value="C:Program FilesMicrosoft Visual Studio 8SDKv2.0BinResGen.exe" />
 
<target name="build.myProject">
  <exec program="${resgen.exe}" workingdir=".">
      <argline="Strings.resx Strings.resources /str:cs" />
  </exec>

  <

csc target="library" output="MyLibrary.dll" debug="false">

    <resources>
      <include name="**.resources"/>
    </resources>
    <sources>
      <include name="**.cs"/>
    </sources>
  </csc>
</target>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s