2

I have a project with a few post-build event commands. These commands take some time to complete and also have console output. If it matters, the commands are PowerShell commands/scripts. What I've found is Visual Studio will act like it is not responding while the commands execute. Once the commands have all executed, the entire output displays in the Output window in VS when the build finishes. What I'd like is for the Output window to display the console output as it happens so when my scripts run I would see "Beginning command execution...", "Command 1 complete, beginning command 2...", something like that. Is this possible?

Here's what my post-build event commands look like:

if "$(ConfigurationName)" == "Release" "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" Set-ExecutionPolicy Unrestricted
if "$(ConfigurationName)" == "Release" "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -file "$(SolutionDir)\installshieldAutomationScript.ps1"
if "$(ConfigurationName)" == "Release" "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" Set-ExecutionPolicy Restricted

Here's a snippet of my PowerShell script:

Write-Host "Running post-build script..." -ForegroundColor "Green"

#Do a bunch of stuff here
Write-Host "Post-build script complete!" -ForegroundColor "Cyan"
HotN
  • 4,216
  • 3
  • 40
  • 51
  • I've updated my question and added code snippets. – HotN Jun 12 '13 at 16:36
  • @Yvette I haven't yet come up with a great solution if you're still interested in the challenge. I might revisit Meredith's answer but it seems to me that answer would involve creating additional windows, which feels like it defeats the purpose of using the Output window for displaying the scripted output. – HotN Jun 13 '13 at 13:37

1 Answers1

0

Can you put an "[System.Windows.Forms.Application]::DoEvents()" between the PowerShell commands? Without it you aren't allowing the form event handler to process a repaint between each command. You would need this immediately after the Write-Host line.

I see a good write-up here: Powershell Job Event Action With Form Not Executed

Community
  • 1
  • 1
Meredith Poor
  • 351
  • 2
  • 9
  • This didn't work. I'm guessing it's because Visual Studio is not a WinForms application? – HotN Jun 12 '13 at 18:20
  • The link included above shows the complete process. Basically you include the System.Windows.Forms library and instantiate a Windows form with a command button. Just adding DoEvents() by itself won't do much. – Meredith Poor Jun 12 '13 at 21:17