setup.ps1 922 B

1234567891011121314151617181920212223242526272829303132
  1. param($action)
  2. $ErrorActionPreference = 'Stop'
  3. # From http://zduck.com/2012/powershell-batch-files-exit-codes/
  4. function Exec
  5. {
  6. [CmdletBinding()]
  7. param (
  8. [Parameter(Position=0, Mandatory=1)]
  9. [scriptblock]$Command,
  10. [Parameter(Position=1, Mandatory=0)]
  11. [string]$ErrorMessage = "Execution of command failed.`n$Command"
  12. )
  13. & $Command
  14. if ($LastExitCode -ne 0) {
  15. throw "Exec: $ErrorMessage"
  16. }
  17. }
  18. $root = "C:\FrameworkBenchmarks\HttpListener"
  19. $msbuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
  20. # Stop
  21. Get-Process | Where-Object { $_.Name -ieq "HttpListener" } | Stop-Process
  22. if ($action -eq 'start') {
  23. # Build the project
  24. Exec { & $msbuild "$root\HttpListener.sln" /p:DownloadNuGetExe=true /p:RequireRestoreConsent=false /p:Configuration=Release /t:Rebuild }
  25. Start-Process "$root\HttpListener\bin\Release\HttpListener.exe"
  26. }