在MsBuild中,如何运行PowerShell并报告所有错误 [英] In MsBuild, how do I run something PowerShell and have all errors reported
问题描述
可能重复:
任何好的PowerShell MSBuild任务?
Powershell不似乎有一个简单的方法来触发它与任意的命令,然后冒泡解析和执行错误的方式正确地与不是PowerShell的调用者互操作 - 例如, cmd.exe
, TeamCity 等等。
我的问题很简单。对于OOTB MSBuild v4和PowerShell v3,最好的方式是什么(开放的建议 - 不会排除适当的生产就绪MSBuild任务,但它需要比建议很容易 - 采取PowerShell任务工厂示例和运行命令(小脚本段,或(最常见的)调用 .ps1
脚本。 / p>
我认为这应该是正常的,如:
; Exec
IgnoreStandardErrorWarningFormat =true
Command =PowerShell& quot; $(ThingToDo)& quot;/>
悲伤不行: -
- 如果
ThingToDo
无法解析,它会以静默方式失败 - 如果
ThingToDo
是不存在的脚本调用,如果要传播ERRORLEVEL
基于<$ c - $ C> .CMD 结果,如果你想在
ThingToDo $ c $中嵌入
引号,它会变得毛茸茸
- c>,它不会工作
那么,MSBuild运行PowerShell的防弹方式是什么?有没有什么可以 PsGet 使一切正常?
您可以使用以下示例:
< InvokeScript Condition =..
PowerShellProperties =...
ScriptFile =[PATH TO PS1 FILE]
Function =[功能在PS1中呼叫]
参数=。 ..
RequiredOutputParams =...>
<! - 您可以捕获项目中的输出 - >
< Output TaskParameter =OutputResults
ItemName =Output/>
< / InvokeScript>
这可以在MSBuild中使用。
Possible Duplicate:
Any good PowerShell MSBuild tasks?
Powershell doesn't seem to have an easy way to trigger it with an arbitrary command and then bubble up parse and execution errors in a way that correctly interoperates with callers that are not PowerShell - e.g., cmd.exe
, TeamCity etc.
My question is simple. What's the best way for me with OOTB MSBuild v4 and PowerShell v3 (open to suggestions-wouldnt rule out a suitably production ready MSBuild Task, but it would need to be a bit stronger than suggesting "it's easy - taking the PowerShell Task Factory sample and tweak it and/or becoming it's maintainer/parent") to run a command (either a small script segment, or (most commonly) an invocation of a .ps1
script.
I'm thinking it should be something normal like:
<Exec
IgnoreStandardErrorWarningFormat="true"
Command="PowerShell "$(ThingToDo)"" />
That sadly doesn't work:-
- if
ThingToDo
fails to parse, it fails silently - if
ThingToDo
is a script invocation that doesn't exist, it fails - if you want to propagate an
ERRORLEVEL
based.cmd
result, it gets hairy - if you want to embed
"
quotes in theThingToDo
, it won't work
So, what is the bullet proof way of running PowerShell from MSBuild supposed to be? Is there something I can PsGet to make everything OK?
You can use the following example:
<InvokeScript Condition="..."
PowerShellProperties="..."
ScriptFile="[PATH TO PS1 FILE]"
Function="[FUNCTION TO CALL IN PS1]"
Parameters="..."
RequiredOutputParams="...">
<!-- You can catch the output in an Item -->
<Output TaskParameter="OutputResults"
ItemName="Output" />
</InvokeScript>
This can be used in MSBuild.
这篇关于在MsBuild中,如何运行PowerShell并报告所有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!