|
| 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] $help, |
| 29 | + [Parameter(ValueFromRemainingArguments=$true)][String[]]$properties |
| 30 | +) |
| 31 | + |
| 32 | +# Unset 'Platform' environment variable to avoid unwanted collision in InstallDotNetCore.targets file |
| 33 | +# some computer has this env var defined (e.g. Some HP) |
| 34 | +if($env:Platform) { |
| 35 | + $env:Platform="" |
| 36 | +} |
| 37 | +function Print-Usage() { |
| 38 | + Write-Host "Common settings:" |
| 39 | + Write-Host " -configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)" |
| 40 | + Write-Host " -platform <value> Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild" |
| 41 | + Write-Host " -verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)" |
| 42 | + Write-Host " -binaryLog Output binary log (short: -bl)" |
| 43 | + Write-Host " -help Print help and exit" |
| 44 | + Write-Host "" |
| 45 | + |
| 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 | + |
| 61 | + Write-Host "Advanced settings:" |
| 62 | + Write-Host " -projects <value> Semi-colon delimited list of sln/proj's to build. Globbing is supported (*.sln)" |
| 63 | + Write-Host " -ci Set when running on CI server" |
| 64 | + Write-Host " -excludeCIBinarylog Don't output binary log (short: -nobl)" |
| 65 | + Write-Host " -prepareMachine Prepare machine for CI run, clean up processes after build" |
| 66 | + Write-Host " -warnAsError <value> Sets warnaserror msbuild parameter ('true' or 'false')" |
| 67 | + Write-Host " -msbuildEngine <value> Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)." |
| 68 | + Write-Host "" |
| 69 | + |
| 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 | + |
| 74 | +. $PSScriptRoot\tools.ps1 |
| 75 | + |
| 76 | +function InitializeCustomToolset { |
| 77 | + if (-not $restore) { |
| 78 | + return |
| 79 | + } |
| 80 | + |
| 81 | + $script = Join-Path $EngRoot 'restore-toolset.ps1' |
| 82 | + |
| 83 | + if (Test-Path $script) { |
| 84 | + . $script |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +function Build { |
| 89 | + $toolsetBuildProj = InitializeToolset |
| 90 | + InitializeCustomToolset |
| 91 | + |
| 92 | + $bl = if ($binaryLog) { '/bl:' + (Join-Path $LogDir 'Build.binlog') } else { '' } |
| 93 | + $platformArg = if ($platform) { "/p:Platform=$platform" } else { '' } |
| 94 | + |
| 95 | + if ($projects) { |
| 96 | + # Re-assign properties to a new variable because PowerShell doesn't let us append properties directly for unclear reasons. |
| 97 | + # Explicitly set the type as string[] because otherwise PowerShell would make this char[] if $properties is empty. |
| 98 | + [string[]] $msbuildArgs = $properties |
| 99 | + |
| 100 | + # Resolve relative project paths into full paths |
| 101 | + $projects = ($projects.Split(';').ForEach({Resolve-Path $_}) -join ';') |
| 102 | + |
| 103 | + $msbuildArgs += "/p:Projects=$projects" |
| 104 | + $properties = $msbuildArgs |
| 105 | + } |
| 106 | + |
| 107 | + MSBuild $toolsetBuildProj ` |
| 108 | + $bl ` |
| 109 | + $platformArg ` |
| 110 | + /p:Configuration=$configuration ` |
| 111 | + /p:RepoRoot=$RepoRoot ` |
| 112 | + /p:Restore=$restore ` |
| 113 | + /p:DeployDeps=$deployDeps ` |
| 114 | + /p:Build=$build ` |
| 115 | + /p:Rebuild=$rebuild ` |
| 116 | + /p:Deploy=$deploy ` |
| 117 | + /p:Test=$test ` |
| 118 | + /p:Pack=$pack ` |
| 119 | + /p:IntegrationTest=$integrationTest ` |
| 120 | + /p:PerformanceTest=$performanceTest ` |
| 121 | + /p:Sign=$sign ` |
| 122 | + /p:Publish=$publish ` |
| 123 | + @properties |
| 124 | +} |
| 125 | + |
| 126 | +try { |
| 127 | + if ($clean) { |
| 128 | + if (Test-Path $ArtifactsDir) { |
| 129 | + Remove-Item -Recurse -Force $ArtifactsDir |
| 130 | + Write-Host 'Artifacts directory deleted.' |
| 131 | + } |
| 132 | + exit 0 |
| 133 | + } |
| 134 | + |
| 135 | + if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) { |
| 136 | + Print-Usage |
| 137 | + exit 0 |
| 138 | + } |
| 139 | + |
| 140 | + if ($ci) { |
| 141 | + if (-not $excludeCIBinarylog) { |
| 142 | + $binaryLog = $true |
| 143 | + } |
| 144 | + $nodeReuse = $false |
| 145 | + } |
| 146 | + |
| 147 | + if ($restore) { |
| 148 | + InitializeNativeTools |
| 149 | + } |
| 150 | + |
| 151 | + Build |
| 152 | +} |
| 153 | +catch { |
| 154 | + Write-Host $_.ScriptStackTrace |
| 155 | + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message $_ |
| 156 | + ExitWithExitCode 1 |
| 157 | +} |
| 158 | + |
| 159 | +ExitWithExitCode 0 |
0 commit comments