通过 powershell 执行时,Msbuild 日志不起作用 [英] Msbuild log doesn't work when executed through powershell

查看:98
本文介绍了通过 powershell 执行时,Msbuild 日志不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用批处理文件调用 msbuild.exe 时,日志记录功能工作正常.

When i am using batch file for invoking msbuild.exe ,logging functionality works fine.

但是当它用 powershell 编写时,它不会记录任何内容.

But when it is written in powershell ,it doesn't log anything.

以下是我正在使用的 powershell 脚本.知道如何解决这个问题吗?

Following is the powershell script i am using . Any idea how to solve this?

# Script to invoke build
. ./vsvars32.ps1

Remove-Item "ViewBuild1.log"

$MsbuildBinPath="C:\Windows\Microsoft.NET\Framework\v4.0.30319"


$errorLogFileName="ViewBuild1Errors.log"
$buildLogFileName="ViewBuild1.log"

$MSBuildLogger="/flp1:Append;LogFile=ViewBuild1.log;Verbosity=Normal; /flp2:LogFile=ViewBuild1Errors.log;Verbosity=Normal;errorsonly"

$MSBuildFile="Build.Targets"

Write-Host --------------------------------------------
Write-Host Prepare for the build
Write-Host --------------------------------------------
&"$MsbuildBinPath\Msbuild.exe" $MSBuildFile "/t:Prepare"  "$MSBuildLogger"
if ($LastExitCode -ne 0) {
Write-Host "It failed, send a mail"
} 
#$LastExitCode

&"$MsbuildBinPath\Msbuild.exe" $MSBuildFile "/t:BuildAll"  "$MSBuildLogger"

虽然我在文件记录器中使用了附加选项,但执行后 Viewbuild1.log 根本没有内容.

Viewbuild1.log has no contents at all after executing though i have used append option in filelogger.

推荐答案

$MSBuildLogger 的所有内容都作为单个参数传递给 MSBuild,例如:

All of $MSBuildLogger is passed as a single argument to MSBuild e.g.:

PS> $MSBuildLogger="/flp1:Append;LogFile=ViewBuild1.log;Verbosity=Normal; /flp2:LogFile=ViewBuild1Errors.log;Verbosity=
Normal;errorsonly"
PS> echoargs $MSBuildLogger
Arg 0 is </flp1:Append;LogFile=ViewBuild1.log;Verbosity=Normal; /flp2:LogFile=ViewBuild1Errors.log;Verbosity=Normal;erro
rsonly>

尝试使用两个变量:

PS> $MSBuildLogger1="/flp1:Append;LogFile=ViewBuild1.log;Verbosity=Normal;"
PS> $MSBuildLogger2="/flp2:LogFile=ViewBuild1Errors.log;Verbosity=Normal;errorsonly"
PS> echoargs $MSBuildLogger1 $MSBuildLogger2
Arg 0 is </flp1:Append;LogFile=ViewBuild1.log;Verbosity=Normal;>
Arg 1 is </flp2:LogFile=ViewBuild1Errors.log;Verbosity=Normal;errorsonly>

仅供参考,echoargs.exe 是来自 PowerShell 社区扩展 的实用程序.

FYI, echoargs.exe is a utility from the PowerShell Community Extensions.

这篇关于通过 powershell 执行时,Msbuild 日志不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆