Sunday, December 9, 2007

NAnt Build Script Improvement - Being Pragmatic

For the last six months our team has dealt with the annoyance of forgetting to close our Report.txt file before running the test target of our NAnt Script. If you have no clue what I am talking about I will give you a little bit of background on our build process. Our team does not use Visual Studio to build our projects. Rather we use a NAnt script. Our NAnt Script has a target called "test" that runs all tests in the solution using an xunit framework. The results of the test are written to a notepad file in the same directory where the code is built. If the Report.txt file is not closed before running the test target you receive an error that the directory is in use. This error occurs because the build script is trying to delete a directory where a file is in use. Even though we only waste several seconds a day or minutes in a week we decided to get pragmatic about the problem. One of our developers created a target called KillNotePad that uses a SysInternals tool called PsKill. PsKill is a program that allows you to specify the process name or id that you would like to terminate(kill). Please be warned that this will kill all instances of Notepad. Fortunately, I do not use notepad but NotePad++. Therefore when I kill notepad notepad++ stays open. The build script I am using is very similar to the one described on Jp's blog you can also find it in the Nothing But .Net source code from November 2007 http://jpboodhoo.googlecode.com/svn/trunk/ 

The original clean target simply tries to delete the build and deploy directory and fails if the Report.txt file is open.

<target name="clean" >

  <delete dir="${build.dir}" />

</target>

The new clean target is now dependant on the killNotePad target. This means that the KillNotepad target will be run before the clean target.


<target name="clean" depends="KillNotepad">

  <delete dir="${build.dir}" />

</target>

 

<target name="KillNotepad">

  <exec

        program="${tools.dir}\pskill.exe"

        commandline="notepad.exe"

        failonerror="false"/>

</target>

The following is just one example of how you can solve this problem. The wonderful thing is that we do not all think alike. I'm sure that you can come up with a different solution a better solution.

 

3 comments:

Scott said...

I've used unlocker on the command line to unlock the mbunit report txt file so it'll let notepad stay open, but let you delete the file since its no longer being used.

Anonymous said...

miley cyrus nude miley cyrus nude miley cyrus nude

marko said...

Assumable advances are likewise favored without anyone else's input utilized individuals on the grounds that for properties tolerating assumable exchanges does not require the borrower to make an alternate arrangement of agreement for acquiring the property as the property can be brought through the current arrangement of agreement.check cashing