Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How-To Integrate IIS 7 Web Deploy with MSBuild (TeamCity)

How-To Integrate IIS 7 Web Deploy with MSBuild (TeamCity) ?

like image 638
Yoann. B Avatar asked May 17 '10 08:05

Yoann. B


2 Answers

Troy Hunt has an excellent 5-part blog series that goes over this topic in detail.

He has effectively compiled all of the other resources out there and turned them into a tutorial.

It's the clearest (and believe it or not, the most concise) way to do what you want.

like image 195
Noah Heldman Avatar answered Oct 09 '22 12:10

Noah Heldman


I finally managed to get it to work after several days of struggle. It finally boils down to a MSBuild script, installing and configuring web deploy on the staging/test server and setting it up in Team City.

It's a lot of steps and all can go wrong. I will investigate further and blog about it but this is my first attempt that works.

I'm using this setup:

  • .NET 4
  • ASP.NET MVC 2
  • TFS 2008
  • Team City
  • IIS7
  • Web Deploy

Here is the MSBuild script:

    <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">     <PropertyGroup>         <Configuration>Release</Configuration>         <Platform>AnyCPU</Platform>     </PropertyGroup>      <Import Project="Webapplication.csproj" />      <Target Name='Deploy' DependsOnTargets='Build;Package' >         <Exec Command='"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe"                  -source:contentpath="$(teamcity_build_checkoutDir)\Main\source\Webapplication\obj\Release\Package\PackageTmp\"                  -dest:contentpath="c:\inetpub\Webapplication\www",includeAcls=false,computername="https://(stagingserver-name):8172/msdeploy.axd?Site=Webapplication",authType=Basic,userName=(staginserver-name)\webdeploy,password=********                  -allowUntrusted                  -verb:sync' />     </Target> </Project> 

Key points:

  • I set up the Web.Release.config to work in the staging environment
  • The build script must be located in the same directory as Webapplication.csproj
  • Web deploy must be installed on the Team City server as well as on the web (staging) server
  • c:\inetpub\Webapplication\www is a directory on the web server
  • The webdeploy username is a local windows account on the web server with full access to c:\inetpub\Webapplication\www

Preparations:

  • I followed the steps at http://technet.microsoft.com/en-us/library/dd722796(WS.10).aspx
  • I followed part 1 at http://learn.iis.net/page.aspx/516/configure-the-web-deployment-handler/
  • and created a contentPath rule for c:\inetpub\Webapplication\www and all users

Team City:

I set up a new build configuration using the MSBuild script above and set the target to Deploy

like image 43
Rickard Avatar answered Oct 09 '22 11:10

Rickard