运行Python脚本以从MSBuild进行部署

Gha*_*han 1 deployment msbuild python-2.7

我有一个正在进行部署的python脚本.我想从msbuild运行该脚本并获取输出,以防它通过或失败.那么,如何与msbuild进行状态通信和错误文本?我想在构建服务器上显示结果.我必须使用python 2.7,并且不能使用3.x.

sti*_*ijn 5

使用Exec任务运行命令并捕获它的输出.例如:

<Target Name="GetPythonOutput">

  <PropertyGroup>
    <PyCommand>/path/to/python.exe -a /path/to/pthonfile</PyCommand>
    <TempFile>ExecTempFile</TempFile>
  </PropertyGroup>

  <Exec Command="$(PyCommand) &gt; $(TempFile)" />

  <ReadLinesFromFile File="$(TempFile)">
    <Output TaskParameter="Lines" ItemName="PyOutput"/>
  </ReadLinesFromFile>
  <Delete Files="$(TempFile)" />

  <Message Text="Python command output was: @(PyOutput)" />
</Target>
Run Code Online (Sandbox Code Playgroud)

如果您使用的是.Net 4.5,那么事情会更好,因为Exec 可以为您完成大部分工作