views:

122

answers:

1

Let's consider the below example. There, I have:

  1. target MAIN call target t then call target tt.
  2. target t call target ttt, target tt call target tttt.
  3. target t define property aa, target ttt modify aa.
  4. target tttt try to print property aa 's value.
  5. in short we have: MAIN -> {t -> {ttt->modify aa, define aa}, tt -> tttt -> print aa}

But in target tttt, we can't "see" aa's updated value (by ttt)! Please help me to make that value visible to target tttt. Thank you!

The whole script is as below:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="MAIN" >
  <Target Name="MAIN" >
    <CallTarget Targets="t" />
    <CallTarget Targets="tt" />
  </Target>

  <Target Name="t">
    <Message Text="t" />
    <PropertyGroup>
      <aa>1</aa>
    </PropertyGroup>
    <CallTarget Targets="ttt" />
  </Target>

  <Target Name="tt">
    <Message Text="tt" />
    <CallTarget Targets="tttt" />
  </Target>

  <Target Name="ttt">
    <PropertyGroup>
      <aa>122</aa>
    </PropertyGroup>
    <Message Text="ttt" />
  </Target>

  <Target Name="tttt">
    <Message Text="tttt" />
    <Message Text="tttt:$(aa)" />
  </Target>

</Project>
+1  A: 

As already said in an answer to another post you should model your MSBuild project with dependencies between your Targets rather than calling Targets one after another.

<Project DefaultTargets="tttt" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    <Target Name="t">
        <Message Text="t" />
            <PropertyGroup>
                <aa>1</aa>
            </PropertyGroup>
     </Target>

     <Target Name="tt" DependsOnTargets="t">
         <Message Text="tt" />
     </Target>

     <Target Name="ttt" DependsOnTargets="t;tt">
         <PropertyGroup>
             <aa>122</aa>
         </PropertyGroup>
         <Message Text="ttt" />
     </Target>

     <Target Name="tttt" DependsOnTargets="t;tt;ttt">
         <Message Text="tttt" />
         <Message Text="tttt:$(aa)" />
     </Target>
</Project>

An approach I use, is to define a Target as my final goal, putting it into the projects DefaultTargets.

Then add all the things that need to happen to achieve this goal.

Filburt