• Home /
  • Blog /
  • Creating build system from scratch using TeamCity and Microsoft Web Deploy
Teamcity Webdeploy

Creating build system from scratch using TeamCity and Microsoft Web Deploy

The blog post will explain how to create build system and deploy application code to different environments, such as DEV, UAT, PROD… using TeamCity and MSDeploy. The application which need to be deployed is an ASP.NET MVC 4 application, but it does not matter, it can be any web application (ASP.NET, ASP.NET MVC, HTML app).

Build server

I assume you already have TeamCity installed on your build server, but if you don’t have it, you can get the latest version from JetBrains. In my case I used TeamCity 8.0.2 installed on Windows Server 2008R2 (but it does not matter, it works on Windows 8 and Windows Server 2012 the same way)

Download and install TeamCity from http://www.jetbrains.com/teamcity/

Also your build server require the following software installed, in order to perform deployment using Web Deploy

  • Microsoft Web Platform Installer (it will be used to install all dependencies)
  • .NET Framework 4 (this is only in case you building application targeting .NET 4 framework)
  • TeamCity
  • Visual Studio Express for Web

You have to install Visual Studio Express for Web on build server, otherwise you will get the following error message:

error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

You can install Visual Studio Express using Web Platform installer. The web edition of Visual studio is less then 100 Mb visual studio express for web But in case if you don’t want to install visual studio, you can just copy content of WebApplications folder from your local machine (I am sure you have visual studio installed on your machine, so the folder will be there) to build server.

Web Server

There are some requirements for the web server as well: you have to install the following software on web server in order to Web Deploy works properly.

  • Microsoft Web Platform Installer (it will be used to install all dependencies)
  • Web Deploy 3.5
  • Web Deploy 3.5 for Hosting Servers
  • Web Deployment Tool 2.1

The easiest way to install all required software is to use Web Platform Installer web-deploy Make sure then you have .net 4 installed, and .net version for application pool is 4.0 as well

TeamCity project

After you install Teamcity you have to create a new project. teamcity create new project Give Project a name and press “Create” button create project On the next screen you need to add a new build configuration add build configuration Give a name to build configuration and go to Source control settings by clicking “VCS settings” button name build configuration Now you need to add your source control system add vcs root I prefer Git, but it does not matter, you can use Subversion or TFS, or different providers which Teamcity support. git source control In my case the authentication method is Anonymous, because I used GitHub public repository, but in case if you use Bitbucket or SVN you can provide username/password or upload Private key. git anonymous

Do not forget to press “Test Connection” button before saving your source control configuration.

Next step will be to add a “build step”. TeamCity supports a number of build runner, but I prefer to use MSBuild

In case of more complex build system, you probably have some build steps before and after main "deployment" step, for example I have iisreset step, because sometimes logging system does not allow to republish application when IIS process is running. In that case add new build step with runner type "Command line" and in Custom script field type iisreset

build steps settings

Command line parameter explanation

/P:Configuration=%environment-name% /P:DeployOnBuild=True /P:DeployTarget=MSDeployPublish /P:MsDeployServiceUrl=https://%destination-server%:8172/MsDeploy.axd /P:AllowUntrustedCertificate=True /P:MSDeployPublishMethod=WMSvc /P:CreatePackageOnPublish=True /P:UserName=%destination-server-user% /P:Password=%destination-server-password% /p:DeployIisAppPath="Default Web Site/myapp-%environment-name%"
Configuration - by default, when you create project in Visual Studio, you have two configuration Debug and Release, but you can create as many configuration as you need, for example: UAT, SIT, PROD... and during deployment MSBuild will transform your web.config file with configuration you provided. For example one of my project has a number of different options for configuration and different transformation files: configuraiton manager data config MsDeployServiceUrl - after you install Web Deploy package on web server, it creates service on port 8172 which is responsible for publishing web applications to IIS MSDeployPublishMethod - when you use basic authentication (using username/password) you have to use WMSvc Username - User who has administrator permissions on webserver Password - Password for the user DeployIISAppPath - location where you want to deploy your web application, in my case I am not deploying it to root of website, but you can deploy it to "Default Web Site" or you can create your own website and provide it's name there. In my case app deployed to http://servername/myapp-release

Now navigate to build parameters and give values to configuration parameters build parameters And the build is ready. Try to run it, by pressing “Run” button at the top right corner. After the build finished, you can see the following result build successful And application is deployed on target web server deployed app For different environment you have to create the same build project, but provide different "Build parameters" (EnvironmentName, DestinationServer...), the best way to do it, is to copy existing project and modify it's properties: copy project   uat parameters And your final build projects can look like this: real project


Yaplex - Freelance developer - white logo on black background

Yaplex is a custom software development company co-founded by full-stack .NET Software developer Alex Shapovalov who lives in Mississauga, ON and provides software development services in Mississauga and GTA.

Contact Information

Mississauga, ON, Canada
Phone: +1 647 328 3809
Email: alex@yaplex.com