DCSIMG
July 2010 - Posts - Roy Rosenberg

Roy Rosenberg

Team System and ALM Consultant

July 2010 - Posts

Log Build Messages in Custom Build Activity in Team Build 2010

In TFS 2008 when we create custom tasks (inherits from Task class), we get a log object which helps us log messages into the log file of the build (with LogMessage method).

 

In TFS 2010 the Team Build is based on workflow, so when we create a code activity we inherit from Activity class that does not contain log object. Not even a log method. Instead, we have context object (of CodedActivityContext class) that has Track method that can execute another activity.

 

We can Create new WriteBuildError Activity object (from the toolbox) and pass it to Track method. When running the build, we will have new line in the build log with our message.

 

A better way to do it is to use Microsoft.TeamFoundation.Build.Workflow.Activities namespace that contains extension methods for the context. After adding the using statement, you'll notice 3 new methods of the context called TrackBuildError, TrackBuildWarning and TrackBuildMessage. Enjoy!

 

 

Team Build 2010: Copy each solution into separate directory inside drop location folder?

Most of my customers want their Drop Location folders organized in sub-folders for each solution instead of getting all DLLs\EXEs in one massy folder.

 

Instead of customizing csproj as http://stackoverflow.com/questions/2784335/how-can-i-get-tfs-2010-to-build-each-project-to-a-separate-directory  and http://social.msdn.microsoft.com/Forums/en/tfsbuild/thread/a62a6f98-ec44-46c1-a0d0-7f441f0db973 suggest, you can update the template of your build and change the output directory to the one you want.

 

First, open the XAML template and drill down to the compilation activity:

MSBuild Task

 You have Run-MSBuild-for-Project activity. In the Properties window check out the OutDir parameter – That's the one you want to change!

By default, this parameter has outputDirectory variable which directs to Binaries folder of the build in the build machine.


i.e I created a build name TestBuild.

The default OutDir value is D:\Builds\4\Project2010\TestBuild\Binaries


Now, for creating a new folder for each solution, update OutDir parameter with this code:

System.IO.Path.Combine(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(localProject))

 

The Build Will automatically copy OutDir content to the DropLocation folder. Have Fun