In answer to the further question -
"is there anyway to apply this within the Visual Studio project? In a multi-developer environment, if someone else check's out the code on their machine, then their local IIS Express wouldn't be configured with the virtual directory and cause runtime errors wouldn't it?"
I never found a consistant answer to this anywhere but then figured out you could do it with a post build event using the XmlPoke task in the project file for the website -
<Target Name="AfterBuild">
<!-- Get the local directory root (and strip off the website name) -->
<PropertyGroup>
<LocalTarget>$(ProjectDir.Replace('MyWebSite\', ''))</LocalTarget>
</PropertyGroup>
<!-- Now change the virtual directories as you need to -->
<XmlPoke XmlInputPath="..\..\Source\Assemblies\MyWebSite\.vs\MyWebSite\config\applicationhost.config"
Value="$(LocalTarget)AnotherVirtual"
Query="/configuration/system.applicationHost/sites/site[@name='MyWebSite']/application[@path='/']/virtualDirectory[@path='/AnotherVirtual']/@physicalPath"/>
</Target>
You can use this technique to repoint anything in the file before IISExpress starts up. This would allow you to initially force an applicationHost.config file into GIT (assuming it is ignored by gitignore) then subsequently repoint all the paths at build time. GIT will ignore any changes to the file so it's now easy to share them around.
In answer to the futher question about adding other applications under one site:
You can create the site in your application hosts file just like the one on your server. For example:
<site name="MyWebSite" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\GIT\MyWebSite\Main" />
<virtualDirectory path="/SharedContent" physicalPath="C:\GIT\SharedContent" />
<virtualDirectory path="/ServerResources" physicalPath="C:\GIT\ServerResources" />
</application>
<application path="/AppSubSite" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\GIT\AppSubSite\" />
<virtualDirectory path="/SharedContent" physicalPath="C:\GIT\SharedContent" />
<virtualDirectory path="/ServerResources" physicalPath="C:\GIT\ServerResources" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:4076:localhost" />
</bindings>
</site>
Then use the above technique to change the folder locations at build time.
applicationHost.config
file is under the project root:${PROJECT}\.vs\config\applicationHost.config
. – Matt