Summary: Adding a solution and building it using TeamCity and MsBuild
This is the second post in my TeamCity series, the first post is TeamCity: Easy Continuous Integration
After going through the setup process, and setting up the admin user this page will open up:

Here simply click on Create project.

In this demo I am going to add my CodePlex solution. Note that if you have a serious Open source project you can apply for a hosted Continuous Integration server at TeamCity.CodeBetter.com (more about it here).

Simply click on “add a build configuration”.

Here the only thing you must do is add a name.
Option you can consider changing: “Fail build if: it runs longer that _ minutes”. Though there is a detection on if a build hangs I had once received a Unit Test(integration) failure for a test that had a timeout after an hour because the service it tried to access hanged. Because of this I think you should wait and see what your average build time is, add to it 5 minutes and set that number here.

Before setting the Source Control folder we should really set our server.

These are the options of available Source Control systems, in this case I am going to setup Team Foundation Server (TFS).

Pretty straightforward set the VCS root name otherwise TeamCity generate a folder with a weird name. If in the setup phase you entered a SYSTEM account (like me) than please enter your user/password. If this TFS server is used in several solutions you would like to add that mark the V in “Make this VCS root available to all of the projects”.
Click on “Test connection” to test your settings, you should get a popup such as:

Close the popup and click on save.

“Checkout directory” is a bit misleading this is just the name of the local folder that will be used by TeamCity.
Note that if your build changes the source files in anyway you should check “Clean all files before build” (though this step will cause a slower build). Personally I found it best on the first couple of runs to check this option on since it ensures the solution has all the files (and you never know what build action someone else has set that might hurt your build).
Continue to “Add Build Step”.

The next step is setting up the build with MsBuild, you can give the step a name though it is optional, in “Build file path” enter the path to the solution file from VCS root (from the setting of TFS Source Control). In my case the file is under the folder DllShepherd so I entered DllShepherd\DllShepherd.sln.
Now simply enter the solution .net version, in my case .net 4.0. The ToolsVersion could always be set to 4.0 (if you have .net 4.0 installed) since MsBuild supports compilation to older versions.
Click on “Save” to continue.
On the right side:

Click on “Build Triggering”.
Here we are going to add two triggers:
1. Changes in the Source Code:

Quiet period mode: wait 60 seconds for other changes before building
In “Trigger rules” you can setup that the build won’t be triggered if the only change was in a html file:
-:**.html
You can read more about other options here.
2. Schedule – every day at 3 AM:

The only change (apart from the time) to the trigger was unchecking “Trigger build only if there are pending changes” since we want the build to run everyday (and we already have a build when the source control is changed).
The next section on the right panel is for Dependencies to other projects. I didn’t have any but it seems easy enough to set. You can even skip it all together by creating a large solution that contains all of your projects (though build times will suffer).
All the other sections on the right panel can be kept on their default values.
The only thing remaining is clicking on “Run” to test the settings:
My first run failed with this error:
(396, 5): Running transformation: System.Exception: T4MVC can only execute through the Visual Studio host
Since I used T4 build with TextTemplating that is support in VS but not in MsBuild. Removing it, checking “Clean all files before build” (since the T4 build deleted one of the source control files – because it tried to recreate it and failed) and reconnecting to the internet (for some odd reason my connection died):

And that it.
Note: Though I didn’t show it TeamCity is not just for .Net:

The next post will be on adding Unit Tests to the mix (I promise it’s going to be shorter).
Resources:
Announcing TeamCity.CodeBetter.com
TeamCity MsBuild help