setup_iis.ps1 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. $wwwroot = "C:\FrameworkBenchmarks\aspnet\www"
  19. $source = "C:\FrameworkBenchmarks\aspnet\src"
  20. $msbuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
  21. # Stop
  22. if (Get-WebSite -Name Benchmarks) { Remove-WebSite -Name Benchmarks }
  23. Get-ChildItem -Path $wwwroot -Recurse -ErrorAction 'SilentlyContinue' | Remove-Item -Force -Recurse -ErrorAction 'SilentlyContinue' | Out-Null
  24. Remove-Item -Force -Recurse $wwwroot -ErrorAction 'SilentlyContinue' | Out-Null
  25. if ($action -eq 'start') {
  26. # Create a website in IIS
  27. New-Item -Path $wwwroot -Type Directory -ErrorAction 'SilentlyContinue' | Out-Null
  28. New-WebSite -Name Benchmarks -Port 8080 -PhysicalPath $wwwroot
  29. # Build the project
  30. Exec { & $msbuild "$source\Benchmarks.AspNet.csproj" /t:RestorePackages }
  31. Exec { & $msbuild "$source\Benchmarks.AspNet.csproj" /p:Configuration=Release /p:Platform=x64 /t:Clean }
  32. Exec { & $msbuild "$source\Benchmarks.AspNet.csproj" /p:Configuration=Release /p:Platform=x64 /p:DeployOnBuild=true /p:PublishProfile=IIS }
  33. }