views:

30

answers:

1

I'm using the fabulous albacore gem with rake to build a new .NET project. My organization is still using NAnt, and there are lots of folks who expect to see a log file when the build script executes. How do I save the msbuild task output that gets dumped to STDOUT to a log file?

A: 

I figured out a solution. We don't really need a build log file for our CI server (hudson), but it would still be nice to have physical files to check when the build runs locally, particularly when we're doing the check-in dance and the build fails.

Fortunately, the albacore dudes were smart enough to create a ".parameters" option, which can be used with any of the command-line tool tasks to add parameters which aren't explicitly handled by that task. So, for example, you can add a parameter to the msbuild task to specify a logfile for MSBuild. And it goes a little something like this:

BUILD_REPORTS = 'BuildReports'
MSBUILD_EXE = "C:/Windows/Microsoft.NET/Framework/v4.0.30319/msbuild.exe"

directory BUILD_REPORTS

CLEAN.include BUILD_REPORTS

task :default => [:build]

desc "Build the solution"
msbuild :build => BUILD_REPORTS do |msb|
    msb.properties :configuration => :Debug
    msb.path_to_command = MSBUILD_EXE
    msb.targets :Clean, :Build
    msb.solution = "./mysolution.sln"
    msb.parameters "/l:FileLogger,Microsoft.Build;logfile=" + log_file("build")
end

def log_file(log_file_name)
    BUILD_REPORTS + log_file_name + ".log"
end

Our rakefile is a little more complex than that because it has to do more stuff, but you get the idea.

dalesmithtx