How to create a web site with an application using MSBuild Extension Pack

3

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>
iis-7
msbuild
msbuildcommunitytasks
asked on Stack Overflow Oct 29, 2009 by Jason

1 Answer

2

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>

Discussed further here

answered on Stack Overflow Oct 31, 2009 by Mike Fourie • edited Dec 7, 2012 by Adam

User contributions licensed under CC BY-SA 3.0