7 May
2004

Parsing .csproj with nAnt

The Problem

Using the solution task in nAnt,
I need to be able to distribute non-buildable project items into my build environment.
You know the problem. My project has an XSD in it, or my project directory has a README.TEXT
that may not even be a project item. With our automated build process, these items
need to simply be copied into the build directory via nAnt.

The Solution

Parse the .csproj file using nAnt, it is XML after all. Slingshot just
seems like overkill for this problem, so how about just using XSLT?

Step 1 Create an XSLT file to parse my project file and output a
mini nAnt script that performs a file copy. We are interested in project items that
have a BuildAction=”Content”.

Step 2 Forcibly copy all items in the “OtherFiles“ folder
to the build environment.  This enables a developer to include items in his build
package that aren’t included as items in the VS project at all.

Step 3 Then use nAnt’s <style> task to hand the project file
to this XSL and transform it into a mini nAnt script.

Step 4 Call the mini nAnt script from the master build script with
the <nant> task.

Here is the mini script that was created in step 3.

Find me

RSS
Facebook
LinkedIn

Disclaimer

The opinions and content expressed here are my own and not those of my employer.