sdk-task.ps1 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. [CmdletBinding(PositionalBinding=$false)]
  2. Param(
  3. [string] $configuration = 'Debug',
  4. [string] $task,
  5. [string] $verbosity = 'minimal',
  6. [string] $msbuildEngine = $null,
  7. [switch] $restore,
  8. [switch] $prepareMachine,
  9. [switch] $help,
  10. [Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
  11. )
  12. $ci = $true
  13. $binaryLog = $true
  14. $warnAsError = $true
  15. . $PSScriptRoot\tools.ps1
  16. function Print-Usage() {
  17. Write-Host "Common settings:"
  18. Write-Host " -task <value> Name of Arcade task (name of a project in SdkTasks directory of the Arcade SDK package)"
  19. Write-Host " -restore Restore dependencies"
  20. Write-Host " -verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]"
  21. Write-Host " -help Print help and exit"
  22. Write-Host ""
  23. Write-Host "Advanced settings:"
  24. Write-Host " -prepareMachine Prepare machine for CI run"
  25. Write-Host " -msbuildEngine <value> Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)."
  26. Write-Host ""
  27. Write-Host "Command line arguments not listed above are passed thru to msbuild."
  28. }
  29. function Build([string]$target) {
  30. $logSuffix = if ($target -eq 'Execute') { '' } else { ".$target" }
  31. $log = Join-Path $LogDir "$task$logSuffix.binlog"
  32. $outputPath = Join-Path $ToolsetDir "$task\\"
  33. MSBuild $taskProject `
  34. /bl:$log `
  35. /t:$target `
  36. /p:Configuration=$configuration `
  37. /p:RepoRoot=$RepoRoot `
  38. /p:BaseIntermediateOutputPath=$outputPath `
  39. @properties
  40. }
  41. try {
  42. if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) {
  43. Print-Usage
  44. exit 0
  45. }
  46. if ($task -eq "") {
  47. Write-PipelineTelemetryError -Category 'Build' -Message "Missing required parameter '-task <value>'" -ForegroundColor Red
  48. Print-Usage
  49. ExitWithExitCode 1
  50. }
  51. $taskProject = GetSdkTaskProject $task
  52. if (!(Test-Path $taskProject)) {
  53. Write-PipelineTelemetryError -Category 'Build' -Message "Unknown task: $task" -ForegroundColor Red
  54. ExitWithExitCode 1
  55. }
  56. if ($restore) {
  57. Build 'Restore'
  58. }
  59. Build 'Execute'
  60. }
  61. catch {
  62. Write-Host $_.ScriptStackTrace
  63. Write-PipelineTelemetryError -Category 'Build' -Message $_
  64. ExitWithExitCode 1
  65. }
  66. ExitWithExitCode 0