Web Deploy (MS Deploy) from TeamCity

I use TeamCity as a continuous integration server but also as a build/deploy server. With the click of a button, TeamCity will build my solution, run unit tests and automatically deploy my web application to a server. This is awesome because:
  1. It saves tons of time as it automates the process.
  2. It ensures the integrity of the build before deploying (compile, run tests, halt if error).
  3. It allows me to encapsulate deployment logic so that there are no manual, “magic” steps involved with deployment. When I go on vacation, another developer can deploy my app with the same button click I use.
I could go on and on about the advantages of using a CI/build/deploy server for development but here I want to explain how to setup TeamCity to use the new Web Deploy (MS Deploy) tool to deploy ASP.NET Web Application projects to a server running IIS.

Setup Steps

  1. Install the Web Deployment Tool on your TeamCity server and the server you want to deploy your web application to (“target server”).
  2. On your target server, setup an administrator user account for use by TeamCity.
  3. Create a new project in TeamCity.
  4. Under Project Configuration, select “Build Parameters” option.
  5. Add Configuration Parameters and System Properties per the example below.
  6. Change the values highlighted in yellow above to your own values. A few notes:
    • build.file.directory = this is the relative checkout path of the folder which contains your web application .csproj file
    • system.DeployIISAppPath = the IIS website name on the target server which you want to deploy to. Yes, this means you need to configure IIS ahead of time if you are going to use anything other than the “Default Web Site” in IIS.
    • system.MsDeployServiceUrl = the server name or IP address of the target server.
    • system.UserName / system.Password = the username and password of the administrator account you setup earlier for the target server.
  7. Under Project Configuration, select “Build Steps” option and add a new Build Step (MSBuild runner type).
  8. Configure the new build step per the example below:
  9. Save the new TeamCity project.
  10. Run the project build and you’re done! The web application will be compiled and deployed to your server running IIS.

Next Steps

  • Utilize Web.config Transformations so that your web.config file can be automatically changed to environment specific setting at deployment time.
  • Add a TeamCity build step to your project to run your unit tests before the MsBuild step.
  • Read up on the Web Deployment Handler and fine tune it to your needs.
  • Use “IIS Manager” permission to avoid having to use an administrator account on the target server.

Credit and Reference

  • Jeff

    Does VS 2010 need to be installed on the TeamCity build server? For me it just runs _CopyWebApplicationLegacy to the bin folder.

  • Brady

    I do have VS 2010 installed on my build server but don’t believe it should be needed as this the above technique is simply calling MsBuild / MsDeploy and not using anything with VS.

  • http://jasonwingfield.com Jason

    Thanks Brady – very helpful post!

    I made 2 changes to get this working for my build:

    1) set system.DeployIISAppPath to “Default Web Site/MyWebAppName”
    2) set system.MSDeployPublishMethod to “RemoteAgent”. Using your setting threw an exception during publish that my agent wasn’t running, even though I could publish manually from studio.



  • http://www.robertdougan.co.uk Robert Dougan

    Thanks for the post!

    I’ve followed all the steps but I can’t get my site to publish at all. I can publish from Visual Studio no problem but not from TeamCity. From the build log it looks as if it doesn’t even try to run MSDeploy.

    I’m wondering if I’m missing something really obvious?


  • Brady

    Try to setup another simple build project that only runs MSBuild with your project file and see if it succeeds. Then add the system properties mentioned above and see if that makes it fail. Then you will have more insight into what is going on. Did you install the Web Delployment Tool (mentioned above) on your TeamCity server?

  • http://www.robertdougan.co.uk Robert Dougan

    Ah, I got it to work. I was building a Visual Web Developer Express solution file, which I guess must not support WebDeploy publishing?

    When I tried to build and deploy with a VS 2010 Professional project file it worked first time!

    Thanks for replying!

  • moh_kin

    You’r absolutely right about no need VS 2010 to be installed, nor MSDeploy if you will attach it with the project solution as a library exe or something.
    But indeed you will actually need VS 2010 installed to make the build compile first especially for web application projects.

  • John Dhom

    Typically you’d install the [.Net portion] Windows SDK instead of Visual Studio on your build server, for the usual reasons (licensing, keeping the build server clean and easy to setup, etc.).

    Best, /jhd

  • John Dhom

    Nice post, good information. I’ve taken a different approach… which is to product the website.zip file during the CI build so I can deploy the package to dev then [same package] to QA and so on.

    I’m now in search of how to setup a deploy build that uses the build artifacts from the ci build. If you have any references you can share I’d appreciate it.

    Best, /jhd

  • moh_kin

    I tried that but it failed for some specific project types especially ASP.NET MVC 3 projects.
    Also for licensing issue, you could install VS 2010 Web Expression.

  • Lasse Schou

    To get MS Deploy working on the teamcity server when Visual Studio is not installed (which it shouldn’t), you need to copy a few files from your dev machine:

    From the C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0 folder on your dev machine copy the “Web” and “Web Applications” folders to the equivalent directory on your build server.

  • Geoffrey Hogg

    A great web page, a huge help.

    I need to delete the web site, and then redeploy it leaving two directories untouched since they are large, and unchanging.

    MSDeploy has the verb delete, and skip fields, but I have no idea how to map these to the TeamCity Build Parameters. Surely delete is a completely separate step previous to deployment.

    Any ideas?

    Thanks, Geoff

  • Brady

    Try adding a system property called SkipExtraFilesOnServer (alongside the other TeamCity system properties shown above) and set the value to true. By default this option is false.

  • DIP

    I have a problem with web deployment using WMSvc method.
    I am getting exception like “On the destination computer, make sure that Web Deploy is installed and that the required process (“The Web Management Service”) is started.)
    The requested resource does not exist, or the requested URL is incorrect.
    Error details:
    Could not connect to the destination computer. On the destination computer, make sure that Web Deploy is installed and that the required process (“The Web Management Service”) is started.
    The remote server returned an error: (404) Not Found.”

    But I have installed Web Deployment tool, and started the Web Management service in the target machine.
    Using Remote agent method I can able to deploy it on the targer server.

    Any Idea’s how to resolve this problem?

  • Sebastiaan Janssen

    Thank you very much for this, it is so much easier to follow these steps than go through the whole seperate build configuration that Troy uses in his (AWESOME) blog series.

    The only thing that I had to change was the system.MsDeployServiceUrl it had to look like this: https://yourserver.whatever:8172/msdeploy.axd

    Also, for the copy/pasters out there, instead of trying not to make spelling errors, here’s the configuration in text format:

    Configuration Parameters
    build.file.directory YourSite\
    build.file.projectName YourSite.csproj

    System Properties (system.)
    system.AllowUntrustedCertificate true
    system.Configuration Release
    system.CreatePackageOnPublish true
    system.DeployIISAppPath YourIISSite
    system.DeployOnBuild true
    system.DeployTarget MSDeployPublish
    system.ExcludeApp_Data true
    system.MSDeployPublishMethod WMSvc
    system.MsDeployServiceUrl https://YourServerName.Something:8172/msdeploy.axd
    system.PackageLocation obj\%system.Configuration%\Package\%build.vcs.number.1%_package.zip
    system.Password YourPassword
    system.SkipExtraFilesOnServer true
    system.UserName YourDomain\YourAdministratorUser

  • Pingback: Continuous Deployment for ASP.NET using Git, MSBuild, MSDeploy, and TeamCity | 'enehana - technology()

  • Diego

    @sebastian – The setting “system.SkipExtraFilesOnServer true” is not working for me… is this working for you?

  • http://bbs.0359fh.com/forum.php?mod=viewthread&tid=216244 you have something to start with in finding the right flower girl dresses15

    You are my intake, I own few blogs and rarely run out from brand . “He who controls the past commands the future. He who commands the future conquers the past.” by George Orwell.