17 July 2015

This post has the intention to ease future Team City installations for me and hopefully also other people out there. For the moment I will not be very specific in how to perform all the steps involved to get everything up and running. Instead I will just give a list of references and hints. I may extend this post in the future. Since I am a .NET guy, I will focus on installing stuff to build and package .NET applications.

0. State of the art

  • TeamCity Version to install = 9.1
  • Server = Windows Server 2012 R2
  • Database = Sql Server 2014
  • .NET Version = 4.6
  • VS Version = 2015

1. Install Team City

Start with the obvious. Grab the Team City installation files from JetBrains here and run the installer.

If you want to use Microsoft SQL Server for the database backend, you also need the sqljdbc driver which can be obtained here. The driver has to be placed in TeamCity Data Directory/lib/jdbc where on my system TeamCity Data Directory = C:\ProgramData\JetBrains\TeamCity – see also here for further information.

Note: The Professional Server license is free and allows up to 3 build agents and 20 build configurations. Of course, both limits can be extended by purchasing additional licenses.

1.1 Build Agent User Configuration

The user running the build agents need several additional permissions – see https://confluence.jetbrains.com/display/TCD9/Setting+up+and+Running+Additional+Build+Agents.

In particular, the user needs the permissions

  • Logon as a service
  • Reboot the machine
  • Start/Stop TCBuildAgent service

The first two can be configured using the Local Security Policy, while for the third one it is convenient to use the tool SubInACL provided by Microsoft here.

.\subinacl /service TCBuildAgent /grant=YOURMACHINE\YOURUSER=top

The default installation path is *C:\Program Files (x86)\Windows Resource Kits\Tools*

2. Install MS Build Tools

See also https://confluence.jetbrains.com/display/TCD9/MSBuild for further details.

3. Install additional MS Build targets

You may encounter the following error when building web applications

The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\ Microsoft.WebApplication.targets" was not found.

You can easily fix this by copying the C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0 from your machine to the TeamCity build agent.

4. Install Nuget

To be able to use nuget package restore during your build, follow the instructions here. You can also setup your TC Server to serve a Nuget feed of your builds.

5. Install Git

If you want to have TC check out source code from your git repositories, you need to install Git for Windows.

6. Install Visual Studio Test Agents

Install MSTest.exe to allow TeamCity to run Unit Tests designed using the Microsoft Testing Framework.

7. Connect with Visual Studio Online


8. GitVersionTask

If you want to use GitVersionTask Version 2.x, then there are several issues with Team City. One is that the whole git repository has to be checked out to perform the build and not just the branch you are building. To do that go to Project Settings -> Build -> Edit -> Version Control Settings -> VCS checkout mode: Automatically on agent. Doing so requires the agent to have access to the git repository. One possibility to achieve this is to store the git credentials in the environment variables of the user running the build agent.

!! This may introduce serve security issues especially when you are using the same build agent for different clients !!

See also https://github.com/ParticularLabs/GitVersion/issues/379.

9. Code Contracts

If you want to use code contracts, install the latest version of them on your build agent.

You may also want to alter your project files to run code contracts as a build step.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <!-- Begin CodeTools: CodeContracts: After -->
        <CodeContractsInstallDir Condition="'$(CodeContractsInstallDir)'==''">C:\Program Files (x86)\Microsoft\Contracts\</CodeContractsInstallDir>
    <Import Condition="'$(CodeContractsImported)' != 'true' AND '$(DontImportCodeContracts)' != 'true'" Project="$(CodeContractsInstallDir)MsBuild\v12.0\Microsoft.CodeContracts.targets" />
    <!-- End CodeTools: CodeContracts: After -->

X. What is missing

The possibilities to use TeamCity to automate your build process are endless and therefore this manual is far from complete. Any questions, comments, and suggestions to extend it are welcome.

blog comments powered by Disqus