See the question and my original answer on StackOverflow

Web project files in Visual Studio are Xml files. Consequently, IIS vs Cassini settings are stored in plain sight Xml. You can programmatically modify them using only any Xml api.

There is an example of such a work here: Programmatically change Web project settings from dynamic port to static, although it's not changing the web server type, it's exactly the same idea.