Share via


MSBuild Task

Builds MSBuild projects from another MSBuild project.

Parameters

The following table describes the parameters of the MSBuild task.

Parameter Description

Projects

Required ITaskItem[] parameter.

Specifies the project files to build.

Properties

Optional String parameter.

A semicolon-delimited list of property name/value pairs to apply as global properties to the child project. Specifying this parameter is functionally equivalent to setting properties with the /property switch when building with MSBuild.exe. For example:

Properties="Configuration=Debug;Optimize=$(Optimize)"

RebaseOutputs

Optional Boolean parameter.

If true, the relative paths of target output items from the built projects have their paths adjusted to be relative to the calling project. Default is false.

RunEachTargetSeparately

Optional Boolean parameter.

If true, the task runs each target with a separate invocation. This means that subsequent targets will be built even if previously invoked targets failed. Default is false.

StopOnFirstFailure

Optional Boolean parameter.

If true, forces the task to stop building the remaining projects as soon as any of them fail.

TargetOutputs

Optional ITaskItem[] read-only output parameter.

Returns the outputs of the built targets from all the project files. Only the outputs from the targets that were specified are returned, not any outputs that may exist on targets that those targets depend on.

The TargetOutputs parameter also contains the following metadata:

  • MSBuildProjectFile: The MSBuild project file that contains the target that set the outputs.

  • MSBuildTargetName: The target that set the outputs.

NoteNote

If you want to identify the outputs from each project file or target separately, run the MSBuild task separately for each project file or target. If you run the MSBuild task only once to build all the project files, the outputs of all the targets are collected into one array.

Targets

Optional String parameter.

Specifies the target or targets to build in the project files. Use a semicolon to separate a list of target names. If no targets are specified in the MSBuild task, the default targets specified in the project files are built.

NoteNote

The targets must exist in all the project files. If they do not, a build error occurs.

Remarks

Unlike using the Exec Task to invoke MSBuild.exe, this task uses the same MSBuild process to build the child projects. The list of already-built targets that can be skipped is shared between the parent and child builds. This task is also faster because no new MSBuild process is created.

This task can process not only project files but also Visual Studio 2005 solution files.

Example

The following example uses the MSBuild task to build the projects specified by the ProjectReferences item collection. The resulting target outputs are stored in the AssembliesBuiltByChildProjects item collection.

<Project xmlns="https://schemas.microsoft.com/developer/msbuild/2003">

    <ItemGroup>
        <ProjectReferences Include="*.*proj" />
    </ItemGroup>

    <Target Name="BuildOtherProjects">
        <MSBuild
            Projects="@(ProjectReferences)"
            Targets="Build">
            <Output
                TaskParameter="TargetOutputs"
                ItemName="AssembliesBuiltByChildProjects" />
        </MSBuild>
    </Target>

</Project>

See Also

Concepts

MSBuild Tasks

Other Resources

MSBuild Task Reference