Build and publish .Net 2.0 projects with NAnt and the MSBuild task – level 200

.Net 2.0 first came out, I was left using the <exec
task to call msbuild.exe to build my solution.  The NAnt <solution
task is specific to .Net 1.1 because Microsoft change the structure
of project files to be MSBuild scripts.

I may be a little behind on this, but NAntContrib now contains a
<msbuild /> task that can either just build your solution or execute an
entire msbuild script.  Here is an excerpt from my NAnt build script:

<target name=compile>

       <echo message=Build Directory is ${build.dir} />

       <msbuild project=src/xxx.sln>

              <arg value=/property:Configuration=release />                                  

              <arg value=/t:Rebuild />




The task brings the full power of MSBuild to NAnt.  At first, I thought about converting the
entire build to MSBuild, but I have so much invested in NAnt that I can’t
justify the effort of conversion yet since we won’t gain anything.  For now, we’ll have a mixed build process. 


Later when we need to package with ClickOnce, we can use the
<msbuild /> task with the publish target:


<msbuild project=src/xxx.sln>

<arg value=/p:Configuration=${project.config};ApplicationVersion=${project.version}.${CCNetLabel};MinimumRequiredVersion=${project.version}.${CCNetLabel};UpdateRequired=true />

       <arg value=/t:publish />



This node builds the ClickOnce deployment package for our
application.  CruiseControl.Net executes this NAnt
script, so every time we commit code to Subversion,
we build out the ClickOnce install package and commit it back to SVN and tag
it.  No matter what version we need, it’s
right at our fingertips.


By the way, I now always edit my build scripts in VS 2005
since Resharper 2.0 helps
with NAnt scripts.  I can rename targets,
find usages, jump from target to target just as I can in code.  In short, it has refactoring and navigation
support for the build scripts.