2

I am working on automation of deployment process and I need to find a way to build and deploy an asp.net web site.

On top of this I would also like to create IIS Site and Application Pool for newly created IIS if one doesn't already exist.

Is this possible with Web Deploy (or is there an even better way/tool/approach to achieve these goals?)

XDS
  • 3,786
  • 2
  • 36
  • 56
Ravi Khambhati
  • 637
  • 1
  • 12
  • 35

2 Answers2

2

Consider using ServerManager class from Miceosoft.Web.Administration namespace. Specifically, ApplicationPools and Sites properties. For example,

ServerManager sm = new ServerManager();
Site site = serverMgr.Sites.Add(“MySiteName”, “C:\\inetpub\\wwwroot”, 8080);
sm.ApplicationPools.Add(“MyAppPool”);
sm.CommitChanges()

For more information see https://msdn.microsoft.com/en-us/library/microsoft.web.administration.servermanager(v=vs.90).aspx

Hope this helps.

Victor Havin
  • 1,023
  • 7
  • 11
1

There's also MSBuildExtensionPack:

https://github.com/mikefourie/MSBuildExtensionPack

I imagine that said msbuild-family-of-actions employs the Microsoft.Web.Administration namespace to work its magic in terms of creating a new website in IIS 7 and the scripting looks something like this (haven't tested this on my own server yet):

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

  <ItemGroup>
    <WebApplication Include="/MyApp">
      <PhysicalPath>$(WebSitePath)</PhysicalPath>
    </WebApplication>
    <VirtualDirectory Include="/MyVdir">
      <ApplicationPath>/MyApp</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>
XDS
  • 3,786
  • 2
  • 36
  • 56