我有一个PowerShell脚本如下
##teamcity[progressMessage 'Beginning build']
# If the build computer is not running the appropriate version of .NET, then the build will not run. Throw an error immediately.
if( (ls "$env:windir\Microsoft.NET\Framework\v4.0*") -eq $null ) {
throw "This project requires .NET 4.0 to compile. Unfortunately .NET 4.0 doesn't appear to be installed on this machine."
##teamcity[buildStatus status='FAILURE' ]
}
##teamcity[progressMessage 'Setting up variables']
# Set up variables for the build script
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
$v4_net_version = (ls …Run Code Online (Sandbox Code Playgroud) 我正在从MSBuild调用PowerShell脚本.MSBuild能够捕获返回的输出,但认为项目已成功构建.
问题是PowerShell的退出代码没有传递给MSBuild中的命令.有人曾经试过这个并且能够向MSBuild抛出退出代码吗?
testmsbuild.proj
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ScriptLocation>c:\scripts\test.ps1</ScriptLocation>
</PropertyGroup>
<Target Name="AfterDropBuild" >
<Exec Command="powershell.exe -NoProfile -Noninteractive -command "& { $(ScriptLocation)%3Bexit $LASTEXITCODE }" " >
<Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
</Exec>
</Target>
</Project>
Run Code Online (Sandbox Code Playgroud)
test.ps1(当然这会出错)
function CallFromMSBuild {
Invoke-command {Powershell.exe C:\a.ps1} -computername $computers
}
Run Code Online (Sandbox Code Playgroud)
当触发MSBuild项目时,它应该已经发现问题并且构建应该失败(认为构建成功了)
当我从MSBuild打电话时
C:\Scripts>msbuild testmsbuild.proj /t:AfterDropBuild
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.225]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 4/28/2011 2:46:29 PM.
Project "C:\scripts\testmsbuild.proj" on node 1 (AfterDropBuild target(s)).
AfterDropBuild: …Run Code Online (Sandbox Code Playgroud) 任何人都知道任何好的MSBuild任务将执行PowerShell脚本并传递不同的参数?
我能够找到B#.NET博客:从MSBuild调用PowerShell脚本,但我希望有一些更精致的东西.
如果我找不到任何东西,我当然会继续使用该博客作为首发来磨练自己.