当我使用批处理文件调用msbuild.exe时,日志记录功能正常。
但是当它在powershell中编写时,它不会记录任何内容。
以下是我正在使用的powershell脚本。知道如何解决这个问题吗?
# 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在执行后根本没有内容,虽然我在filelogger中使用了append选项。
答案 0 :(得分:2)
所有$MSBuildLogger
都作为单个参数传递给MSBuild,例如:
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 Community Extensions的实用程序。
答案 1 :(得分:1)
将整个MSBuild命令作为powershell var进行控制,然后使用Invoke-Command执行它。我这样做,效果很好!
$console_logging_switch = " /clp:Summary"";""Verbosity=$consoleLogLevel"
$file_logging_switch = " /flp:Summary"";""Append"";""LogFile=build.$config.log"";""verbosity=normal"
$file_errlog_switch = " /flp1:Append"";""LogFile=build.$config.err"";""errorsonly"
$file_wrnlog_switch = " /flp2:Append"";""LogFile=build.$config.wrn"";""warningsonly"
$logging_switch = $console_logging_switch + $file_logging_switch + $file_errlog_switch + $file_wrnlog_switch
$targets_switch = " /t:$targets"
$outdir_switch = " /p:OutDir=""$outdir"""
$config_switch = " /p:Configuration=""$config"""
if($skipCodeAnalysis){ $config_switch = " $config_switch /p:RunCodeAnalysis=false " }
if($buildReferences){ $config_switch = " $config_switch /p:BuildProjectReferences=false " }
if($filter -ne $null){ $config_switch = " $config_switch /p:ProjectFilter=$filter " }
$options = $outdir_switch + $config_switch + $logging_switch + $targets_switch
$cmd = "msbuild $project $options"
Invoke-Expression $cmd