Exec powershell.exe挂起msbuild

时间:2013-01-10 23:36:26

标签: visual-studio-2010 powershell msbuild hang

我目前正在考虑重新加入我们的黑客攻击部署系统,使其更加优雅 - 八达通。在这样做时,我试图让VS在运行发布版本时打包项目。好吧,我有这个花哨的PowerShell脚本编写和工作,但当我尝试从msbuild脚本EXEC,视觉工作室只是挂起!

起初我怀疑是什么东西在shell中被逃脱了,但是我把它简化得很荒谬,它仍然冻结。

这是相关的MsBuild代码:

    <PropertyGroup>
      <PowerShellExe Condition=" '$(PowerShellExe)'=='' ">
        %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
      </PowerShellExe>
    </PropertyGroup>

    <Target Name="AfterBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
      <Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted -command get-childitem" />
    </Target>

所有它应该做的是给出一个目录列表。从cmd.exe调用此方法可以正常工作:

C:\Users\smithj>%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -executionpolicy unrestricted -command dir

试试这个:

msbuild Solution.sln /p:Configuration=Release

给我这个:

AfterBuild:
  "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\\tf.exe" che
  ckout Package.nuspec
  Package.nuspec

        %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
       -NonInteractive -executionpolicy Unrestricted -command dir

  Windows PowerShell
  Copyright (C) 2009 Microsoft Corporation. All rights reserved.

之后,它就会永远挂起。欢迎任何建议。

2 个答案:

答案 0 :(得分:28)

不确定你会不会喜欢这个答案。 经过一段时间的游戏,似乎是关于房地产集团的扩张。您在PowerShellExe的值中添加了一个新行。 这很好用:

<PropertyGroup>
    <PowerShellExe Condition=" '$(PowerShellExe)'=='' ">$(WINDIR)\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShellExe>
  </PropertyGroup>

  <Target Name="AfterBuild">
    <Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy bypass -command &quot;&amp;{get-childitem}&quot;" />
  </Target>

答案 1 :(得分:0)

尝试:

<Exec Command='$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted -command "& {Get-ChildItem}"' />