build.ps1 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. [CmdletBinding(PositionalBinding=$false)]
  2. Param(
  3. [string][Alias('c')]$configuration = "Debug",
  4. [string]$platform = $null,
  5. [string] $projects,
  6. [string][Alias('v')]$verbosity = "minimal",
  7. [string] $msbuildEngine = $null,
  8. [bool] $warnAsError = $true,
  9. [bool] $nodeReuse = $true,
  10. [switch][Alias('r')]$restore,
  11. [switch] $deployDeps,
  12. [switch][Alias('b')]$build,
  13. [switch] $rebuild,
  14. [switch] $deploy,
  15. [switch][Alias('t')]$test,
  16. [switch] $integrationTest,
  17. [switch] $performanceTest,
  18. [switch] $sign,
  19. [switch] $pack,
  20. [switch] $publish,
  21. [switch] $clean,
  22. [switch][Alias('bl')]$binaryLog,
  23. [switch] $ci,
  24. [switch] $prepareMachine,
  25. [switch] $help,
  26. [Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
  27. )
  28. function Print-Usage() {
  29. Write-Host "Common settings:"
  30. Write-Host " -configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
  31. Write-Host " -platform <value> Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild"
  32. Write-Host " -verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
  33. Write-Host " -binaryLog Output binary log (short: -bl)"
  34. Write-Host " -help Print help and exit"
  35. Write-Host ""
  36. Write-Host "Actions:"
  37. Write-Host " -restore Restore dependencies (short: -r)"
  38. Write-Host " -build Build solution (short: -b)"
  39. Write-Host " -rebuild Rebuild solution"
  40. Write-Host " -deploy Deploy built VSIXes"
  41. Write-Host " -deployDeps Deploy dependencies (e.g. VSIXes for integration tests)"
  42. Write-Host " -test Run all unit tests in the solution (short: -t)"
  43. Write-Host " -integrationTest Run all integration tests in the solution"
  44. Write-Host " -performanceTest Run all performance tests in the solution"
  45. Write-Host " -pack Package build outputs into NuGet packages and Willow components"
  46. Write-Host " -sign Sign build outputs"
  47. Write-Host " -publish Publish artifacts (e.g. symbols)"
  48. Write-Host " -clean Clean the solution"
  49. Write-Host ""
  50. Write-Host "Advanced settings:"
  51. Write-Host " -projects <value> Semi-colon delimited list of sln/proj's to build. Globbing is supported (*.sln)"
  52. Write-Host " -ci Set when running on CI server"
  53. Write-Host " -prepareMachine Prepare machine for CI run, clean up processes after build"
  54. Write-Host " -warnAsError <value> Sets warnaserror msbuild parameter ('true' or 'false')"
  55. Write-Host " -msbuildEngine <value> Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)."
  56. Write-Host ""
  57. Write-Host "Command line arguments not listed above are passed thru to msbuild."
  58. Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)."
  59. }
  60. . $PSScriptRoot\tools.ps1
  61. function InitializeCustomToolset {
  62. if (-not $restore) {
  63. return
  64. }
  65. $script = Join-Path $EngRoot 'restore-toolset.ps1'
  66. if (Test-Path $script) {
  67. . $script
  68. }
  69. }
  70. function Build {
  71. $toolsetBuildProj = InitializeToolset
  72. InitializeCustomToolset
  73. $bl = if ($binaryLog) { '/bl:' + (Join-Path $LogDir 'Build.binlog') } else { '' }
  74. $platformArg = if ($platform) { "/p:Platform=$platform" } else { '' }
  75. if ($projects) {
  76. # Re-assign properties to a new variable because PowerShell doesn't let us append properties directly for unclear reasons.
  77. # Explicitly set the type as string[] because otherwise PowerShell would make this char[] if $properties is empty.
  78. [string[]] $msbuildArgs = $properties
  79. # Resolve relative project paths into full paths
  80. $projects = ($projects.Split(';').ForEach({Resolve-Path $_}) -join ';')
  81. $msbuildArgs += "/p:Projects=$projects"
  82. $properties = $msbuildArgs
  83. }
  84. MSBuild $toolsetBuildProj `
  85. $bl `
  86. $platformArg `
  87. /p:Configuration=$configuration `
  88. /p:RepoRoot=$RepoRoot `
  89. /p:Restore=$restore `
  90. /p:DeployDeps=$deployDeps `
  91. /p:Build=$build `
  92. /p:Rebuild=$rebuild `
  93. /p:Deploy=$deploy `
  94. /p:Test=$test `
  95. /p:Pack=$pack `
  96. /p:IntegrationTest=$integrationTest `
  97. /p:PerformanceTest=$performanceTest `
  98. /p:Sign=$sign `
  99. /p:Publish=$publish `
  100. @properties
  101. }
  102. try {
  103. if ($clean) {
  104. if (Test-Path $ArtifactsDir) {
  105. Remove-Item -Recurse -Force $ArtifactsDir
  106. Write-Host 'Artifacts directory deleted.'
  107. }
  108. exit 0
  109. }
  110. if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) {
  111. Print-Usage
  112. exit 0
  113. }
  114. if ($ci) {
  115. $binaryLog = $true
  116. $nodeReuse = $false
  117. }
  118. if ($restore) {
  119. InitializeNativeTools
  120. }
  121. Build
  122. }
  123. catch {
  124. Write-Host $_.ScriptStackTrace
  125. Write-PipelineTelemetryError -Category 'InitializeToolset' -Message $_
  126. ExitWithExitCode 1
  127. }
  128. ExitWithExitCode 0