Tuesday, September 09, 2008

Running Visual Studio Web Server as Part of a CI Build

I wanted to get our WatiN acceptance tests to run as part of a CC.Net build.  It was a bit harder than I thought to get the web server up and running before the tests ran so I thought I'd document the steps.

 

  1. Get WebDev.WebHost.dll and WebDev.WebServer2.exe into you solution folder somewhere (I chose SharedLibs\WebServer)
  2. Create a batch file (startserver.bat) that has the line:
    start 
    SharedLibs\WebServer\WebDev.WebServer2.exe
    /port:3699 /path:%~dp0MyProject.Web
  3. Download the Async exec task from here.  Add it to your solution structure.  I put it in SharedLibs\MSBuild.
  4. Add a reference to the AsyncExec task to your ms build file:
    <UsingTask 
         AssemblyFile="SharedLibs\MSBuild\AsyncExec.dll" 
         TaskName="AsyncExec.AsyncExec" />
  5. Execute and kill the server in the msbuild file like this:
        <AsyncExec Command="startserver.bat" />
            
        <Exec ... tests .../> 
    
        <Exec Command="taskkill /F /IM WebDev.WebServer2.exe" 
    IgnoreExitCode="true" />

Notes:

  • Another method might have been to get an IIS site running, but all the tests were set up for local developers to run with the built-in server.
  • The Async exec task is needed as the built-in msbuild task never returns
  • The kill command kills all webdev instances.  This was OK for my solution but may not be for yours!