WebDev.WebServer PowerShell Function

In experimenting with NWSGI yesterday, I found I wanted the ability to launch the development web server that ships with Visual Studio (WebDev.WebServer.exe) from the command line. I hacked up the following PowerShell function and dropped it into my $profile so I can easily launch the web server in any directory any time I need. Thought I’d share:

function webdev($path,$port=8080,$vpath='/')
{
    $spath = 'C:\Program Files\Common Files\microsoft shared\DevServer9.0\WebDev.WebServer.EXE'
    $rpath = resolve-path $path  
    $params = "/path:`"$rpath`" /port:$port /vpath:$vpath"  

    $ignore = [System.Diagnostics.Process]::Start($spath, $params)  
    "Started WebDev Server for '$path' directory on port $port"  
}

There’s probably an easier way to launch an exe with parameters than Sys.Diags.Process.Start, but it works. Using resolve-path is the key, that lets me pass in a relative path on the command line, but the script converts it to an absolute path in order to pass it to the webdev server. Also, I’m not sure I should have hard coded the path to the exe, but again it works and it’s not like it’s tough to change.

Enjoy.

Update: Tomas Restrepo pointed out an easier way to start the process:

&'C:\Program Files\Common Files\microsoft shared\DevServer9.0\WebDev.WebServer.EXE' "/path:$rpath" "/port:$port" "/vpath:$vpath"

I couldn’t figure out how to correctly launch the exe when the physical path to serve has a space in it. Thanks Tomas.

Morning Coffee 159

As you might expect, these morning coffee posts are going to get more dev focused as well as more IPy focused.

  • One of the cool things we showed @ PyCon was Django running on the latest drop of IronPython. IPy lead developer Dino Viehand posted a blog entry (for the first time in 28 months!) showing the basic Python DB provider for SQL Server he put together. Hopefully, we won’t have to wait another two and a half years for Dino’s next post.
  • Speaking of IronPython, some of my new teammates pointed me to Michael Foord’s Planet IronPython aggregate news site. Michael is IPy developer for Resolver Systems (the cool spreadsheet app hybrid I wrote about @ Lang.NET) and he’s working on an IPy book.
  • Still speaking of IPy, Jeff Hardy dropped his first release of NWSGI, an port of Python’s Web Service Gateway Interface spec to ASP.NET and IPy. I can’t wait to see NWSGI combined Django running on IPy like Dino demoed @ PyCon. Congrats Jeff!
  • Scott Hanselman’s post on Twitter reminds me that I recently started twittering myself. I haven’t worked it into my daily routine, so it gets updated only occasionally, but after reading Scott’s post, I’m thinking it’s cooler than it appears on the surface.
  • In surprising news, Microsoft is going to start collaborating with IBM’s Eclipse Foundation, to make it easier to it easier to write apps for Windows in Java. I would think this is a very cool thing, but apparently Ted Neward – who’s knowledge of JavaWorld far eclipses (ha ha) my own – thinks “the skin here is just too sensitive” and that this move might cause more controversy between MS and Java. However, he seems to imply the controversy would be between MS & Sun (Eclipse is obviously named as a jab @ Sun) rather than between MS & the Java community.