Monthly Archives: December 2006

NProject site down

Has some of you might have noticed, the NProject web site is down. was hosting it for free, but due to some abuse, they revoked all the free accounts… If someone knows about a free .NET web host, drop a line!


Filed under NProject

Live coding revisited

I previously bloged about a script that enabled automatic rebuild and restart of the web server on change of the source files. The script was working great, but sometimes some strange errors start poping out.

Thanks to Nick Hemsley who submited a patch that uses FileSystemWatcher, we now get much better results!

I refactored the script a bit and here’s the result:

import System
import System.IO
import System.Threading
import System.Diagnostics

# The command to launch the web server
SERVER_CMD = argv[0]
# Determine if the web server has to be restarted
# afther a built
SERVER_RESTART = argv[1] == 'restart'
# Arguments to send to with the server command
SERVER_ARGUMENTS = join(argv[2:], ' ')

# Arguments to send to nant when building
# Typically the target that builds and some arguments
NANT_ARGUMENTS = 'build -nologo -q'

# Time to wait before watching for changes again
REBUILD_DELAY = 1000 #ms

######## Stop editing here unless you're a damn cool Boo hacker ########
watcher = FileSystemWatcher(Directory.GetCurrentDirectory(), "*.cs")
watcher.IncludeSubdirectories = true
print "Starting live server process, hit CTRL+C to stop"

serverProcess as Process
rebuild = true

while (true):
  print "nant ${NANT_ARGUMENTS}"
  buildProcess = shellp('nant', NANT_ARGUMENTS)
  rebuild = false

  if (buildProcess.ExitCode == 0):
    if SERVER_RESTART or serverProcess == null:
      # Try to stop the server
      if (serverProcess != null):
        except e:
      # Starts the server
      serverProcess = shellp(SERVER_CMD, SERVER_ARGUMENTS)
    print "Build failed! Errors:"
    print '=' * 80
    print buildProcess.StandardOutput.ReadToEnd()
    print '=' * 80
  change = watcher.WaitForChanged(WatcherChangeTypes.All)
  print "File change detected (${change.Name})"

Whenever a .cs file is modified, nant is called to recompile the app and the web server is restarted.

Usage: booi script/ YourWebServer.exe restart|norestart Argument For Your Web Server

On with Mono, you got to enable MONO_MANAGED_WATCHER, or else sub directories wont trigger a rebuild.

booi script/ xsp2 restart --root public $*

If the restart parameter is used, the web server will be restarted on each file change.

This script is now part of Castle Generator. To be as cool as I am, get into live coding:

svn co generator
cd generator
nant install
cd ..
monorail MyBlog
cd MyBlog
nant setup

and start coding!

Leave a comment

Filed under Generator, Monorail