build.ps1 5.8 KB

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