views:

319

answers:

1

What is the correct way to create a web site using the MSBuild Extension Pack?

I'm trying to use the MSBuild Extension Pack to create a web site using the following target. Unfortunately I don't have the syntax correct. This target will throw an exception saying "InvalidOperationException: The specified path already exists.\r". This is after adding the application.

I've tried several different versions of the below target by changing the WebApplication item or the VirtualDirectory item. If I change the Include attribute for the WebApplication item to be something other than "/" then the creation will work. Although once the web site is created I can't start it because of COM error 0x800710D8. (The object identifier does not represent a valid object)

<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>
A: 

Discussed further here

Mike Fourie