How to create a web site with an application on IIS7

Oct 29, 2009 at 7:02 AM

I'm having trouble creating a website using the Iis7Website task.  I asked a similar question on StackOverflow at http://stackoverflow.com/questions/1641765/how-to-create-a-web-site-with-an-application-using-msbuild-extension-pack.

What is the correct syntax to create a web site with an application?

I've tried the following target but it does not work as I would expect.

<Target Name="ProvisionIIS7WebSite" DependsOnTargets="CreateDeploymentNumber">
 
<PropertyGroup>
   
<WebSiteName>$(BaseDeploymentName)$(DeploymentNumber)</WebSiteName>
   
<PortNumber>$(DeploymentNumber)</PortNumber>
 
</PropertyGroup>

 
<ItemGroup>
   
<WebApplication Include="/">
     
<PhysicalPath>$(WebSitePath)</PhysicalPath>
   
</WebApplication>
   
<VirtualDirectory Include="/">
     
<ApplicationPath>/</ApplicationPath>
     
<PhysicalPath>$(WebSitePath)</PhysicalPath>
   
</VirtualDirectory>
 
</ItemGroup>

 
<!-- Create new site -->
 
<MSBuild.ExtensionPack.Web.Iis7Website TaskAction="Create"
   
Name="$(WebSiteName)"
   
Port="$(PortNumber)"
   
Path="$(WebSitePath)"
   
AppPool="$(WebSiteAppPool)"
   
Applications="@(WebApplication)"
   
VirtualDirectories="@(VirtualDirectory)">
   
<Output TaskParameter="SiteID" PropertyName="WebSiteID" />
 
</MSBuild.ExtensionPack.Web.Iis7Website>
 
<Message Text="Created website with ID $(WebSiteID)" />
</Target>
Coordinator
Oct 31, 2009 at 10:56 AM

You need a valid alias, to try

  <ItemGroup>
    <WebApplication Include="/MyApp">
      <PhysicalPath>$(WebSitePath)</PhysicalPath>
    </WebApplication>
    <VirtualDirectory Include="/MyVdir">
      <ApplicationPath>/MyApp</ApplicationPath>
      <PhysicalPath>$(WebSitePath)</PhysicalPath>
    </VirtualDirectory>
  </ItemGroup>