How get exec task output with msbuild

2019-01-10 11:56发布

I'm trying to get simple output by exec task with msbuild:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Test">
    <Exec Command="echo test output">
      <Output TaskParameter="Outputs" ItemName="Test1" />
    </Exec>
    <Exec Command="echo test output">
      <Output TaskParameter="Outputs" PropertyName="Test2" />
    </Exec>
    <Message Text="----------------------------------------"/>
    <Message Text="@(Test1)"/>
    <Message Text="----------------------------------------"/>
    <Message Text="$(Test2)"/>
    <Message Text="----------------------------------------"/>
  </Target>
</Project>

But get next output:

  echo test output
  test output
  echo test output
  test output
  ----------------------------------------
  ----------------------------------------
  ----------------------------------------

How can I get output by my script?

3条回答
戒情不戒烟
2楼-- · 2019-01-10 12:35

Good news everyone! You can now capture output from <Exec> as of .NET 4.5.

Like this:

<Exec ... ConsoleToMSBuild="true">
  <Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>

Simply:

  • Add ConsoleToMsBuild="true" to your <Exec> tag
  • Capture the output using the ConsoleOutput parameter in an <Output> tag

Finally!

Documentation here

查看更多
Animai°情兽
3楼-- · 2019-01-10 12:47

I've gotten to the point where I'm so frustrated with the limitations of MSBuild, and the stuff that's supposed to work but doesn't (at least not in every context), that pretty much anytime I need to do anything with MSBuild, I create a custom build task in C#.

If none of the other suggestions are working, then you could certainly do it that way.

查看更多
戒情不戒烟
4楼-- · 2019-01-10 12:57

You can pipe the output to a file so to speak, and read it back.

echo test output > somefile.txt
查看更多
登录 后发表回答