Tuesday, December 04, 2012

Howto create a build definition on TFS

This morning I had the great idea to setup a build definition and make it run on our TFS server.
This build definition is for an ASP.NET website project that uses also some msbuild tasks. This is how it went.

First let's say that you have your TFS installed and running: at this point congrats to yourself because this is not a small achievement. I'm doing it now...

Then we try to create the build definition. And here we have the first error:

TF225001: Creating a build definition requires a build controller be defined for this team project collection. There may not be any controller configured or you may not have permission to view them

So let's say what google have for us. Here is a guy that explains how to fix this. Be aware that you will need to remote desktop your TFS server to solve this issue and the others I found.
After creating the build controller and agent I found out that I still had the same error. So I double checked and came out that I selected the wrong "Project Collection". So pay attention to select the right collection.
You will also need to create a shared folder for the output of the build: I created a c:\temp folder and shared it as \\server\temp. Yes not a great name but we can change that later (don't name it builds because tfs creates a c:\builds folder and I'm not sure what  will happen if you name it the same: better not to try!).

http://mohamedradwan.wordpress.com/2010/05/15/cant-create-new-build-definition-in-tfs-2010/

Finally you can create your build definition from the team explorer under visual studio (see view menu). It's quite straightforward. You select the probject(s) you need to build and that's and when to build it: for example on every checkin (continuous integration) or on request.

So I tried to build the project(s) and here came the first build error. In our project we are using some msbuild tasks so I needed to install this on the server:

https://github.com/loresoft/msbuildtasks

Tried to build again and here is the next error:

error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.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.

Came out that even Microsoft MVPs and consultants most of the times don't know what they are doing:
http://social.msdn.microsoft.com/Forums/da-DK/tfsbuild/thread/fc5e7c6b-0ecd-4c5f-bda2-e5c7f19221a8

Anyway at the end of the post a user found the solution is to install the VS 2010 shell you can find here:
http://www.microsoft.com/en-us/download/details.aspx?id=115

Next run complains about missing Silverlight SDK so let's install it on the server:
http://www.microsoft.com/en-us/download/details.aspx?id=7335

Try to build agian and... this is funny!
C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.Common.targets (104): The Silverlight 4 SDK is not installed.

But... I just installed it! Ok so let's google for the problem:
http://stackoverflow.com/questions/3001083/msbuild-command-line-error-silverlight-4-sdk-is-not-installed
At the very end of this question a guy having the same problem with tfs suggests the solution:
http://stackoverflow.com/a/9252174/789165

Ok... I feel a little scared but let's try to build it agian.... damn I knew it! So let's see what we have this time:
The type or namespace name 'Interactivity' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

This is an error about Silverlight. But I have the SDK so what am I missing...
http://blakenui.codeplex.com/discussions/228884
oh... the Blend SDK...
http://www.microsoft.com/en-us/download/details.aspx?id=10801
Sorry the Blend SDK for silverlight 4 becasue they are different of course! The other on is for WPF...
http://www.microsoft.com/en-us/download/details.aspx?id=3062

And now what....
The type or namespace name 'NumericUpDown' could not be found (are you missing a using directive or an assembly reference?)
You need to install the silverlight toolkit to fix this:
http://silverlight.codeplex.com/downloads/get/117046

Finally it seemed to work. The very last problem I had was something about the AssembltInfo.cs FileUpdate task we have to update the assembly version on each build. The error was:
The process cannot access the file '...\AssemblyInfo.cs' because it is being used by another process.

It came out that on a project we were referencing too much AssemblyInfo.cs files so I replaced this:

<CreateItem Include="**\AssemblyInfo.cs">
<Output TaskParameter="Include" ItemName="AssemblyInfoFiles" />
</CreateItem>

With this:

<CreateItem Include="$(ProjectDir)Properties\AssemblyInfo.cs">
<Output TaskParameter="Include" ItemName="AssemblyInfoFiles" />
</CreateItem>

This is what I have for now. It's not bad but it's not enough because on the "drop" folder (the folder where tfs puts the output of the build) I don't have the zip files that are generated by the msbuild tasks. I will save this for another day!