是否获取MSBuild以将文件输出到日志?
我有一个输出到文件的程序。我正在从MSBuild项目运行它。我希望将此输出写入StdOut,以便我们的构建代理(TeamCity)能够获取它是否获取MSBuild以将文件输出到日志?,msbuild,Msbuild,我有一个输出到文件的程序。我正在从MSBuild项目运行它。我希望将此输出写入StdOut,以便我们的构建代理(TeamCity)能够获取它 如何让MSBuild将文件内容转储到输出?您应该能够在构建脚本中执行类似的操作(请注意,我正在使用cygwin附带的cat命令输出文件内容)。根据您希望项目在生成过程中运行的时间,可以将目标更改为任何适当的值: <Target Name="AfterGet"> <Exec Command="cat your_file" />
如何让MSBuild将文件内容转储到输出?您应该能够在构建脚本中执行类似的操作(请注意,我正在使用cygwin附带的cat命令输出文件内容)。根据您希望项目在生成过程中运行的时间,可以将目标更改为任何适当的值:
<Target Name="AfterGet">
<Exec Command="cat your_file" />
</Target>
如果您需要在服务器上安装cygwin,您可以获得它。我不知道有哪个本机dos命令可以回送文件内容,但可能有一个。dos命令可以回送文件内容
<Target Name="ExecProgramAndOutputToStdOut">
<Exec Command="YourProgram.exe"/>
<Exec Command="type output_file"/>
</Target>
如果您知道写入文件的位置,可以使用该任务,然后记录所有消息。例如,看看下面的项目文件
<Project DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_File>$(MSBuildProjectFullPath)</_File>
</PropertyGroup>
<Target Name="Demo">
<ReadLinesFromFile File="$(_File)">
<Output ItemName="_FileContents" TaskParameter="Lines"/>
</ReadLinesFromFile>
<Message Text="File contents: '$(MSBuildProjectFullPath)'"/>
<!-- Prints one after another with a ';' between each line -->
<Message Text="@(_FileContents)"/>
<Message Text="-------------"/>
<!-- Prints one after another with each on its own line -->
<Message Text="%(_FileContents.Identity)"/>
</Target>
</Project>
这里重要的一点(我不知道)是Exec总是(?)使用CMD.EXE,这意味着内置命令(如
type
)和重定向在
内部工作。对于linux“cat”,请使用windows“type”
C:\Data\Development\My Code\Community\MSBuild>msbuild ReadLines.proj /nologo
Build started 5/6/2010 6:29:43 PM.
Project "C:\Data\Development\My Code\Community\MSBuild\ReadLines.proj" on node 1 (default targets).
Demo:
File contents: 'C:\Data\Development\My Code\Community\MSBuild\ReadLines.proj'
<Project DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">;<PropertyGroup>;<_Fi
le>$(MSBuildProjectFullPath)</_File>;</PropertyGroup>;<Target Name="Demo">;<ReadLinesFromFile File="$(_File)">;<
Output ItemName="_FileContents" TaskParameter="Lines"/>;</ReadLinesFromFile>;<Message Text="File contents: '$(MS
BuildProjectFullPath)'"/>;<!-- Prints one after another with a ';' between each line -->;<Message Text="@(_FileC
ontents)"/>;<Message Text="-------------"/>;<!-- Prints one after another with each on its own line -->;<Message
Text="%(_FileContents.Identity)"/>;</Target>;</Project>
-------------
<Project DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_File>$(MSBuildProjectFullPath)</_File>
</PropertyGroup>
<Target Name="Demo">
<ReadLinesFromFile File="$(_File)">
<Output ItemName="_FileContents" TaskParameter="Lines"/>
</ReadLinesFromFile>
<Message Text="File contents: '$(MSBuildProjectFullPath)'"/>
<!-- Prints one after another with a ';' between each line -->
<Message Text="@(_FileContents)"/>
<Message Text="-------------"/>
<!-- Prints one after another with each on its own line -->
<Message Text="%(_FileContents.Identity)"/>
</Target>
</Project>
Done Building Project "C:\Data\Development\My Code\Community\MSBuild\ReadLines.proj" (default targets).