views:

17

answers:

1

Hi,

Fairly simple question i imagine but i can't seem to make it work. I'm trying to output the variable from one target, into the parent target which started it. For Example,

Target 1 simply calls the task in file 2, and is supposed to be able to use the variable set within that. However i just can't seem to get it to work (wrong syntax perhaps?) Target 1 looks like this:

 <Target Name="RetrieveParameter">
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="ObtainOutput" />
    <Message Text="Output = $(OutputVar)" />
  </Target>

Target 2, is where it reads in the value of the text file and sets it to the property and sets the variable 'OutputVar' to match. This is supposed to be returned to the parent.

  <Target Name="ObtainOutput" Outputs="$(OutputVar)">
    <ReadLinesFromFile File="output.txt">
      <Output TaskParameter="Lines"
              PropertyName="OutputVar" />
    </ReadLinesFromFile>
  </Target>

I'm quite new to MSBuild tasks, so it could well be something obvious. All i want to do is set a variable in 1 task, then have that available in the parent task which called it.

Many thanks, Chris

A: 

You have to use TargetOutputs of the MSBuild task :

 <Target Name="RetrieveParameter">
   <MSBuild Projects="$(MSBuildProjectFile)" Targets="ObtainOutput">
     <Output TaskParameter="TargetOutputs" ItemName="OutputVar"/>
   </MSBuild>
   <Message Text="Output = @(OutputVar)" />
 </Target>

(More info on MSBuild task).

madgnome