Skip to content

MSBuildTask

mikebridge edited this page May 15, 2012 · 31 revisions

To simplify the calling of the MSBuild.exe, the MSBuildTask can be used in a rakefile. Be sure to require ‘albacore’ at the top of your rakefile, after installing the Albacore gem.

How to use the MSBuildTask

Here is an example of how to use the MSBuildTask

desc "Run a sample build using the MSBuildTask"
msbuild :msbuild do |msb|
  msb.properties = { :configuration => :Debug }
  msb.targets = [ :Clean, :Build ]
  msb.solution = "lib/spec/support/TestSolution/TestSolution.sln"
end

Initializer Parameter: task name (optional)

The default rake task name is “msbuild”. You can specify any name you wish, as the rake task name.

command (optional)

You can specify the location of the MSBuild.exe that you wish to use. If you do not provide a location, then the task will default to using the MSBuild.exe that is included in the .net 3.5 framework.

If an invalid or incorrect msbuild path is specified (i.e. if the file or folder specified does not exist), the MSBuildTask will fail with an exception stating that the msbuild file was not found:

F, [2009-10-04T14:01:33.481000 #5436] FATAL -- : Command not found: i don't exist.exe
F, [2009-10-04T14:01:33.481000 #5436] FATAL -- : MSBuild Failed. See Build Log For Detail
rake aborted!

solution (required)

This is the solution file or msbuild file that you are going to build. This is the one setting for MSBuild that is required. If you don’t provide a valid visual studio solution or msbuild file, you will get an error.

If not solution is provided, the MSBuiltTask will fail with an exception stating that the solution cannot be nil.

F, [2009-09-28T09:42:48.405000 #1048] FATAL -- : solution cannot be nil
rake aborted!
solution cannot be nil

properties (optional)

You can specify any valid MSBuild command line property, here, as a hash literal. For example, if you wanted to provide a property called “foo” with a value of “bar”, and a property called “widget” with a value of “wombat”, you would do so like this:

msb.properties :foo => :bar, :widget => :wombat

You are not required to use :symbols for these values. You can provide string values if you wish. However, if you try to use data types such as “true” or “false”, you must specify them as symbols or strings, directly.

The properties setting is optional. If you don’t provide any values for this, the defaults from your solution or msbuild file will be used.

*Note that albacore in JRuby may yield the error “MSBUILD : error MSB1006: Property is not valid” when using commas in a property. Spaces may be substituted as a workaround:

:nowarn => "0067,0105"
:nowarn => "0067 0105"

IronRuby does not seem to have a problem with commas.

targets (optional)

You can specify any valid target for your solution or msbuild file, here, as an array. The example above is calling the Clean and then Build targets, in that order. If you only want to call Rebuild, as another example, you would set the targets like this:

msb.targets :Rebuild

You are not required to use :symbols for these values. You can provide string values if you wish. However, if you try to use data types such as “true” or “false”, you must specify them as symbols or strings, directly.

The properties setting is optional. If you don’t provide any values for this, the defaults from your solution or msbuild file will be used.

verbosity (optional)

Sets the msbuild “/verbosity” parameter to the specified value.

msb.verbosity = "normal"

This option is separate from the logging options below, as it pertains to the msbuild parameter directly. The logging options below refer to the msbuild task object model.

From MSDN

Displays this amount of information in the build log. Individual loggers display events based upon the verbosity level. A logger can also be configured to ignore the verbosity setting.

The available verbosity levels are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. /v is also acceptable.

loggermodule (optional)

Sets the msbuild “/logger” parameter to the specified value.

msb.loggermodule = JetBrains.BuildServer.MSBuildLoggers.MSBuildLogger,C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MSBuildLoggers.dll

This setting is optional and allows for a logging module to be specified for MSBuild to use, such as the JetBrains TeamCity logger.

This option is separate from the logging options below, as it pertains to the msbuild parameter directly. The logging options below refer to the msbuild task object model.

Logging

The MSBuildTask uses the built in logging options to provide some potentially useful information at run-time. By default, no additional information is logged, other than what MSBuild produces.

verbose mode

When the log_level is set to :verbose, the full command line call for MSBuild will be logged. This includes the expanded path to the msbuild exe as well as the command line parameters that are passed to it.

D, [2009-09-28T09:18:22.254000 #7152] DEBUG -- : Executing MSBuild: "C:\Windows/Microsoft.NET/Framework/v3.5/MSBuild.exe" "TestSolution/TestSolution.sln" /property:configuration=Debug /target:Clean;Build

YAML configuration

This task supports configuration via an external YAML file. For more information, see the yamlconfig page.

Command Line Options

This task supports additional command line options, including a .parameters collection for passing in options that are not directly supported. For more information, see the commandline task options documentation.

Something went wrong with that request. Please try again.