powershell - 在MsBuild中,如何运行PowerShell,并报告所有错误

标签 powershell error-handling msbuild teamcity msbuild-task

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

我的问题很简单。使用OOTB MSBuild v4和PowerShell v3对我来说最好的方法是什么(建议开放-不会排除适合生产的MSBuild Task,但它比建议“要简单-拿PowerShell Task Factory示例和调整它和/或使其成为维护者/父对象”,以运行命令(一个小的脚本段,或者(最常见的)调用.ps1脚本。

我认为这应该是正常的:

<Exec 
  IgnoreStandardErrorWarningFormat="true"
  Command="PowerShell &quot;$(ThingToDo)&quot;" />

不幸的是,这不起作用:
  • 如果ThingToDo解析失败,则默默地失败
  • 如果ThingToDo是不存在的脚本调用,则
  • 失败
  • 如果您要传播基于ERRORLEVEL.cmd结果,它将变得毛茸茸
  • 如果您想在"中嵌入ThingToDo引号,则无法使用

  • 那么,从MSBuild运行PowerShell的防弹方法应该是什么?我可以通过PsGet使一切正常吗?

    最佳答案

    您可以使用以下示例:

    <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>
    

    可以在MSBuild中使用。

    关于powershell - 在MsBuild中,如何运行PowerShell,并报告所有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11648530/

    相关文章:

    unit-testing - 如何在powershell中进行TDD和单元测试?

    powershell - 为 PowerShell 的 Invoke-Expression 转义变量中的字符

    regex - 为什么Powershell Regex.Replace会吞下换行符?

    TFS 2010 构建定义 : MSBuild Arguments seems to be ignored

    msbuild - 使用 Cake 为 .Net Standard 2.0 lib 构建 NuGet 包

    c# - MSBUILD 与 VS2008 构建之间的差异

    powershell - Powershell 2.0的get-CimInstance

    ios - 错误处理 - 错误传播

    Javascript 从索引处的数组获取值,同时如果索引不存在则避免未定义?

    python - 迭代抛出列表,如果值不存在,则隐藏错误并继续