As I blogged about yesterday, I came up with a way to start up the web server that comes with Visual Studio 2005 by right-clicking on the folder you want to serve. Chris Frazier left some great feedback, along with Daniel Fisher.
I think I've solved all the problems that were involved, and there were a few. Besides what I initially talked about, Chris' wrapper solution didn't use the proper virtual path, due to an error in spacing. Daniel's solution went the StringBuilder route for setting up the executable's arguments, which took too much memory. I went the String.Format route, which accomplished the same thing with a lot less code.
I put together an installer that checks for the existence of the webserver executable, copies the wrapper to the .NET runtime directory, and adds the proper registry keys for both Admins and Non-Admins. I've tested it, and it does exactly what I need it to do. Let me know if anyone runs into any problems.
I've been doing some web development work again lately, and I haven't wanted to screw with setting up IIS on my virtual machine. The .NET Framework 2.0 comes with a built-in webserver, based on the old Cassini web server. So I wanted to be able to easily set up any directory to have its contents served up on an as-needed basis. The result is an addition to the Windows Explorer right-click menu, as shown below:
This is enabled by a simple modification to the registry. You can take the text below and dump it into a file named "WebServer.reg", and then run it, to immediately get the item in the context menu.
Windows Registry Editor Version 5.00
@="ASP.NET 2.0 Web Server Here"
@="C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\Webdev.WebServer.exe /port:8080 /path:\"%1\""
There are a couple caveats to this tool, however:
- The web server does not randomly assign a port number, so it has to be hard-coded into the registry.
- The web server does not automatically assign a virtual directory, so it will always be "http://localhost:port"
- A command prompt window will be spawned, and cannot be closed without closing the web server process.
Moving foward, there are a couple of options to fix these issues:
- Someone who knows more about variables in the registry can help me fix issues #2 and #3
- I can build a wrapper executable that solves all three problems
- Microsoft can put in a DCR and fix it before it goes gold in a few days.
#3 is not likely, so I'd love to hear what you think. Hope this trick is useful.
If what Paul says is true, then I will be able to update my MSBuild Toolkit to handle compiling web projects to .NET 1.1
For everyone that has asked, the current version has not been updated for the VS2005 RC builds. I'm going to put out another version for the RTM build of VS2005 that installs cleaner, solves the "mysterious locking" bug, and has a much better UI. I'm just waiting for the actual release to put it out.