TeamCity with VS2012 and .Net4.5 using WebDeploy3.0

Posted : Wednesday, 12 June 2013 07:23:00

I love the whole CI/CD thing and any clients that I have set it up for have benefitted enormously. For my current client I was tasked with reviving and improving the continuous integration that their previous architect had created. I hadn’t used TeamCity before so this was a great chance to jump in. For whatever reason the CI hadn’t been running for a while – the main problem was the build up of incorrect  reference paths – these seem to get added either by ReSharper (which I have paid for and love btw) or as a by product of using a solution build directory. Once we got the build compiling, we began running tests again and the CI server is back keep quality high. My personal drive for doing this is the countless hours I have wasted copying and pasting assemblies, running batch files and editing configuration files in numerous error-prone deployment scenarios.

The next step in the journey was to get a nice automated deployment solution – the first target was a commit-triggered web deploy to IIS. I used this post from Tory Hunt - seriously this is awesome, and of course one from Scott Hanselman. Troy’s was written a few years ago so I think there have been a few changes to visual studio and web deploy. I worked through Troy’s post and along the way a few errors came up, generally about command line parameters being passed to MSBuild. I’ve added a comment for the ones I had to add in addition to those described in Troy and Hanselman’s posts. Hope they benefit someone….

1) The first thing I had to do was install Windows 7.1 SDK developer tools. I *think* this is because there are a couple of WCF services in the solution and the compiler needs to generate the serialization assemblies. SGen.exe is on developer machines because from what i read Visual Studio installs it, and installing Visual Studio on a build server is just wrong, right?

2) In order to get the builds compiling and deploying I had to add/alter some command line parameters, listed below….


        //Debug,Staging,Release etc.

        //%env.Configuration% is configured in TeamCity



        //x86,x64,AnyCPU etc.

        //%env.Platform% is configured in TeamCity



        //solution dir for compilation - required if you use a solution build directory

        //%system.teamcity.build.workingDir% is configured in TeamCity



        //instucts MSBuild to create a deployment package



        //causes the package created to be deployed to /P:MsDeployServiceUrl



        //msbuild target for web deploy



        //msdeploy publish method - recommendation is to use Web Management Service



        //name of IIS site into which this package will be deployed

        //%env.TargetServer% is configured in TeamCity

        //NB user account specified must have permission to do this via IIS Manager

        //or by a local admin on web server



        //path to application in IIS

        //this will be same as /P:MsDeployServiceUrl for root sites

        //or full path if deploying nested application



        //required if using self signed certificate on web server



        //username of account that will be used to deploy application

        //NB must be configured via IIS or be a local admin

        //%deploy.username% is configured in TeamCity



        //password for deployment account

        //%deploy.password% is configured in TeamCity



        //this was required to compile .NET 4.5 applications in VS 2012



        //instructs WebDeploy not to remove files on server

        //preference is not to use this but it may aid debugging deployments



I did this last week and now its running like a dream, the js wizard we have loves it! I’ve created a stable Dev configuration which is manually triggered and has a snapshot dependency on the CI build. During the process of getting this working I found it quickest to create a batch file to run with all the parameters, once that works you can paste the tokenised contents into TeamCity. One gotcha that fooled me for a while was that cutting and pasting to/from TeamCity/Firefox often added carriage returns between the command line arguments, so always worth checking that as I eventually learned.

Since first creating the TeamCity build scripts I have optimised the setup a bit for easy cloning – in short this involved adding TeamCity project system parameters for all the default stuff that is common to all builds. TeamCity will pass any system parameters as command line arguments to MSBuild so it makes the whole thing a bit easier to manage when deploying large numbers of applications.

  • (This will not appear on the site)