通过powershell执行时Msbuild日志不起作用

2024-01-19

当我使用批处理文件调用 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 根本没有任何内容。


All of $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 社区扩展 http://pscx.codeplex.com.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过powershell执行时Msbuild日志不起作用 的相关文章

随机推荐