views:

28

answers:

1

I have created some ms build tasks for my VS project.

Rather than having to update the VS Project file with each of the tasks, is it possible to create an external file to hold the build tasks and reference it via the main project file?

Also, I have seen with nant, that you can create .bat file to run nant tasks. Is it possible to do similar with msbuild?

+2  A: 

Yes. You can use the Import task:

<Import Proejct="PathToMyIncludeFile\Include.proj" />

And yes you can create a batch file to run msbuild. The syntax is

msbuild <project> /t:target[;target] /p:propertyname=propertyvalue

Where the targets are defined in the msbuild file and the properties are any properties defined in the file. If you don't specify a target, the default that is defined in the msbuild file element will be run. Here are a couple of examples:

So to run your build with the Clean, and Compile targets:

msbuild myproject.proj /t:Clean;Compile

Or to run your build with a target of Compile and a release configuration:

msbuild myproject.proj /t:Compile /p:Configuration=Release

Or to run your build with the default target and a set a version property:

msbuild myproject.proj /p:Version=2.0.0.1

Command line parameters take precedence over the values defined in the file. So in the example above if you had the version defined in the file as:

<PropertyGroup>
    <Version>1.0.0.0</Version>
<PropertyGroup>

The build would run with a configured version of 2.0.0.1

As usual, check out MSDN for more info.

Todd