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.
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 "&{get-childitem}"" />
</Target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With