Stopping Casini before (re)building website in Visual Studio

Hi ya’ll,

I sometimes use Casini to debug local web applications. Casini is easy to configure, no need to create a virtual directory, it’s gone after you close Visual Studio so it’s easy.

The problem is that sometimes when changing some code, Casini’s caches aren’t cleared. So you get a stale version of your webpage (or Silverlight or …).

While playing with Powershell I found a little gem called Stop-Process. It even accepts wildcards! Which is nice, since there are 2 WebDev.Webservers. One for .NET 2.0 and one for .NET 4.0.

How can we link this to Visual Studio? Easy. Go to your web project and double-click properties:

Double-click properties

Then go to Build Events, and enter the following text in the Pre-Build event command line (as shown on the picture):

powershell Stop-Process -name webdev.webserver*

Build Events

Next time when you rebuild, Casini will be stopped, and you will always start from a clean page 🙂