views:

473

answers:

2

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

A: 

There is an article from back in December which may address what you are looking to do. I have never done it... Yet, but sure I will be trying. This example outlines using the XmlUpdate task from the MSBuild Community Tasks Project. Hope this helps.

Jeff Spicoli
Can you post the link?
Jeremy Seekamp
Sry... What a dork.... here it is... http://www.compsoft.co.uk/Blog/2009/12/using-msdeploy-as-build-task-in-tfs.html
Jeff Spicoli
That article is actually for Team Foundation Server, not TeamCity.
jrummell
+1  A: 

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"&gt;
    <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:

Team City:

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

Rickard