tags:

views:

477

answers:

2

I have a batch script that I want to call from an MSBuild project, and the documentation says I can't use output from the batch (either console / environment variables) in the MSBuild project.

Is there a workaround?

A: 

I ended up writing a custom MSBuild task that does what I want and return the output.

ripper234
ripper: If this is the Answer, why not mark it as such? Are you willing to share you code?
Nils
It's not marked as such because StackOverflow does't permit me to do so until 48 hours have passed. There's no real code to share - just read any tutorial on writing a custom MSBuild step (the step doesn't return the output to the MSBuild, it simply avoids the need to do so).
ripper234
+2  A: 

You can redirect the output of the command to a file using "> output.txt" and read that into a variable.

<PropertyGroup>
   <OutputFile>$(DropLocation)\$(BuildNumber)\Output.txt</OutputFile>
</PropertyGroup>
<Exec Command="dir > &quot;$(OutputFile)&quot;" />
<ReadLinesFromFile File="$(OutputFile)">
   <Output TaskParameter="Lines" ItemName="OutputLines"/>
</ReadLinesFromFile>
<Message Text="@(OutputLines->'%(Identity)', '%0a%0d')" />
Dave