[ACCEPTED]-How to use an 'Output' parameter from a target in MSBuild-msbuild

Accepted answer
Score: 11

Aside from some minor syntax errors in element 7 case (i.e. target->Target), there are 2 6 main things that need to be fixed to make 5 it work:
1) The TaskParameter attribute 4 should be set to "TargetOutputs"
2) The 3 Outputs attribute of the Sub target need 2 to be surrounded in quotes

This is a working 1 example:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Main">


    <Target Name="Main">
        <Message text="$(MyProp)"/> <!--display 'X'-->
        <CallTarget Targets="Sub">
            <Output TaskParameter="TargetOutputs" PropertyName="MyProp"/>
        <Message text="$(MyProp)"/> <!-- should display 'Y'-->

    <Target Name="Sub" Outputs="$(localProp)">

The above outputs:

Microsoft (R) Build Engine version 4.6.1055.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 5/6/2016 9:51:37 AM.
Project "C:\workspace\dev\msbuild\temp.msbuild" on node 1 (default targets).
Done Building Project "C:\workspace\dev\msbuild\temp.msbuild" (default targets).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.07
Score: 7

You are confusing the Outputs defined on 4 a Target with the Output parameters of a 3 Task.

The Outputs for a Target are used in 2 dependency analysis:

MSBuild Target Element

MSBuild Transforms - Dependency Analysis

The Output parameters 1 of a Task are used to return data:

Simple Example Here

More Related questions