sdk-task.ps1 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /v:$verbosity `
  40. @properties
  41. }
  42. try {
  43. if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) {
  44. Print-Usage
  45. exit 0
  46. }
  47. if ($task -eq "") {
  48. Write-PipelineTelemetryError -Category 'Build' -Message "Missing required parameter '-task <value>'"
  49. Print-Usage
  50. ExitWithExitCode 1
  51. }
  52. if( $msbuildEngine -eq "vs") {
  53. # Ensure desktop MSBuild is available for sdk tasks.
  54. if( -not ($GlobalJson.tools.PSObject.Properties.Name -contains "vs" )) {
  55. $GlobalJson.tools | Add-Member -Name "vs" -Value (ConvertFrom-Json "{ `"version`": `"16.5`" }") -MemberType NoteProperty
  56. }
  57. if( -not ($GlobalJson.tools.PSObject.Properties.Name -match "xcopy-msbuild" )) {
  58. $GlobalJson.tools | Add-Member -Name "xcopy-msbuild" -Value "17.3.1" -MemberType NoteProperty
  59. }
  60. if ($GlobalJson.tools."xcopy-msbuild".Trim() -ine "none") {
  61. $xcopyMSBuildToolsFolder = InitializeXCopyMSBuild $GlobalJson.tools."xcopy-msbuild" -install $true
  62. }
  63. if ($xcopyMSBuildToolsFolder -eq $null) {
  64. throw 'Unable to get xcopy downloadable version of msbuild'
  65. }
  66. $global:_MSBuildExe = "$($xcopyMSBuildToolsFolder)\MSBuild\Current\Bin\MSBuild.exe"
  67. }
  68. $taskProject = GetSdkTaskProject $task
  69. if (!(Test-Path $taskProject)) {
  70. Write-PipelineTelemetryError -Category 'Build' -Message "Unknown task: $task"
  71. ExitWithExitCode 1
  72. }
  73. if ($restore) {
  74. Build 'Restore'
  75. }
  76. Build 'Execute'
  77. }
  78. catch {
  79. Write-Host $_.ScriptStackTrace
  80. Write-PipelineTelemetryError -Category 'Build' -Message $_
  81. ExitWithExitCode 1
  82. }
  83. ExitWithExitCode 0