问题
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?
回答1:
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
回答2:
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.
回答3:
If you want to capture output to an array-like structure and not to a plain string where the output lines are separated by a semicolon, use ItemName instead of PropertyName:
<Exec ... ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" ItemName="OutputOfExec" />
</Exec>
回答4:
You can pipe the output to a file so to speak, and read it back.
echo test output > somefile.txt
来源:https://stackoverflow.com/questions/8938679/how-get-exec-task-output-with-msbuild