Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exec powershell.exe hangs msbuild

I'm currently looking into re-jigging our hacked together deployment system with something a little more elegant - Octopus. In doing so, I'm trying to get VS to package up a project when a release build is run. Well I have this fancy powershell script written and working, but when I try to EXEC from the msbuild script, visual studio just hangs!

At first I suspected the way stuff was being escaped in the shell, but I simplified it ridiculously, and it still freezes.

Here's the relevant MsBuild code:

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

All it should do is give a directory listing. Calling this from cmd.exe works fine:

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

Trying this:

msbuild Solution.sln /p:Configuration=Release

Gets me this:

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.

After that, it just hangs forever. Any suggestions are welcome.

like image 510
monkeybuffer Avatar asked Jan 10 '13 23:01

monkeybuffer


1 Answers

Not sure you're going to like the answer. After a bit of play, it seems to be about the expansion of the property group. You put a new line in the value of PowerShellExe. This works fine:

<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>
like image 159
James Woolfenden Avatar answered Oct 24 '22 15:10

James Woolfenden