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:
- It saves tons of time as it automates the process.
- It ensures the integrity of the build before deploying (compile, run tests, halt if error).
- 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.
- Install the Web Deployment Tool on your TeamCity server and the server you want to deploy your web application to (“target server”).
- On your target server, setup an administrator user account for use by TeamCity.
- Create a new project in TeamCity.
- Under Project Configuration, select “Build Parameters” option.
- Add Configuration Parameters and System Properties per the example below.
- 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.
- Under Project Configuration, select “Build Steps” option and add a new Build Step (MSBuild runner type).
- Configure the new build step per the example below:
- Save the new TeamCity project.
- Run the project build and you’re done! The web application will be compiled and deployed to your server running IIS.
- 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.