2
# Copyright (c) .NET Foundation and contributors. All rights reserved.
3
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
6
[CmdletBinding(PositionalBinding=$false)]
8
[string][Alias('c')]$configuration = "Debug",
10
[string][Alias('v')]$verbosity = "minimal",
11
[string] $msbuildEngine = $null,
12
[bool] $warnAsError = $true,
13
[bool] $nodeReuse = $true,
14
[switch][Alias('r')]$restore,
16
[switch][Alias('b')]$build,
20
[switch] $integrationTest,
21
[switch] $performanceTest,
25
[switch][Alias('bl')]$binaryLog,
27
[switch] $prepareMachine,
30
# official build settings
31
[string]$officialBuildId = "",
32
[string]$officialSkipApplyOptimizationData = "",
34
[Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
37
function Print-Usage() {
38
Write-Host "Common settings:"
39
Write-Host " -configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
40
Write-Host " -verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
41
Write-Host " -binaryLog Output binary log (short: -bl)"
45
Write-Host " -restore Restore dependencies (short: -r)"
46
Write-Host " -build Build solution (short: -b)"
47
Write-Host " -rebuild Rebuild solution"
48
Write-Host " -deploy Deploy built VSIXes"
49
Write-Host " -deployDeps Deploy dependencies (e.g. VSIXes for integration tests)"
50
Write-Host " -test Run all unit tests in the solution"
51
Write-Host " -pack Package build outputs into NuGet packages and Willow components"
52
Write-Host " -help Print help and exit"
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 " -sign Sign build outputs"
56
Write-Host " -publish Publish artifacts (e.g. symbols)"
59
Write-Host "Advanced settings:"
60
Write-Host " -projects <value> Semi-colon delimited list of sln/proj's to build. Globbing is supported (*.sln)"
61
Write-Host " -ci Set when running on CI server"
62
Write-Host " -prepareMachine Prepare machine for CI run"
63
Write-Host " -msbuildEngine <value> Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)."
66
Write-Host "Official build settings:"
67
Write-Host " -officialBuildId An official build id, e.g. 20190102.3"
68
Write-Host " -officialSkipApplyOptimizationData <bool> Pass 'true' to not apply optimization data"
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.)."
74
function Process-Arguments() {
75
function OfficialBuildOnly([string]$argName) {
76
if ((Get-Variable $argName -Scope Script).Value) {
77
if (!$officialBuildId) {
78
Write-Host "$argName can only be specified for official builds"
82
if ($officialBuildId) {
83
Write-Host "$argName must be specified in official builds"
89
if ($help -or (($properties -ne $null) -and ($properties.Contains("/help") -or $properties.Contains("/?")))) {
94
OfficialBuildOnly "officialSkipApplyOptimizationData"
96
if ($officialBuildId) {
97
$script:applyOptimizationData = ![System.Boolean]::Parse($officialSkipApplyOptimizationData)
99
$script:applyOptimizationData = $false
103
$script:binaryLog = $true
104
$script:nodeReuse = $false
108
function Build-Repo() {
109
$bl = if ($binaryLog) { "/bl:" + (Join-Path $LogDir "Build.binlog") } else { "" }
110
$toolsetBuildProj = InitializeToolset
113
# Re-assign properties to a new variable because PowerShell doesn't let us append properties directly for unclear reasons.
114
# Explicitly set the type as string[] because otherwise PowerShell would make this char[] if $properties is empty.
115
[string[]] $msbuildArgs = $properties
116
$msbuildArgs += "/p:Projects=$projects"
117
$properties = $msbuildArgs
120
# Do not set this property to true explicitly, since that would override values set in projects.
121
$suppressPartialNgenOptimization = if (!$applyOptimizationData) { "/p:EnableNgenOptimization=false" } else { "" }
123
MSBuild $toolsetBuildProj `
125
/p:Configuration=$configuration `
126
/p:RepoRoot=$RepoRoot `
127
/p:Restore=$restore `
128
/p:DeployDeps=$deployDeps `
130
/p:Rebuild=$rebuild `
134
/p:IntegrationTest=$integrationTest `
135
/p:PerformanceTest=$performanceTest `
137
/p:Publish=$publish `
138
/p:ContinuousIntegrationBuild=$ci `
139
/p:OfficialBuildId=$officialBuildId `
140
$suppressPartialNgenOptimization `
144
# Set VSO variables used by MicroBuildBuildVSBootstrapper pipeline task
145
function Set-OptProfVariables() {
146
$insertionDir = Join-Path $VSSetupDir "Insertion"
147
$manifestList = [string]::Join(',', (Get-ChildItem "$insertionDir\*.vsman"))
148
Write-Host "##vso[task.setvariable variable=VisualStudio.SetupManifestList;]$manifestList"
151
function Check-EditedFiles() {
152
# Log VSTS errors for changed lines
153
git --no-pager diff HEAD --unified=0 --no-color --exit-code | ForEach-Object { "##vso[task.logissue type=error] $_" }
154
if ($LASTEXITCODE -ne 0) {
155
throw "##vso[task.logissue type=error] After building, there are changed files. Please build locally and include these changes in your pull request."
159
function Check-RequiredVersionBumps() {
160
# Log VSTS errors for missing required version bumps
161
$targetBranch = $env:SYSTEM_PULLREQUEST_TARGETBRANCH
163
# Some PRs specify the bare target branch (most commonly "main"), some prefix it with "refs/heads/".
164
# The following statement normalizes both to a revision spec that git understands.
165
$targetBranch = "refs/remotes/origin/" + ($targetBranch -replace "^refs/heads/", "")
166
$versionLineChanged = $false
167
git --no-pager diff --unified --no-color --exit-code -w $targetBranch HEAD src\Framework\EngineServices.cs `
168
| Select-String -Pattern "int Version =" | ForEach-Object -process { $versionLineChanged = $true }
169
if (($LASTEXITCODE -ne 0) -and (-not $versionLineChanged)) {
170
throw "##vso[task.logissue type=error] Detected changes in Framework\EngineServices.cs without a version bump. " +
171
"If you are making API changes, please bump the version. " +
172
"If the changes in the file are cosmetic, please change an inline comment on the `"int Version =`" line in EngineServices.cs to silence the error."
180
# Import Arcade functions
181
. (Join-Path $PSScriptRoot "common\tools.ps1")
182
. (Join-Path $PSScriptRoot "configure-toolset.ps1")
184
$VSSetupDir = Join-Path $ArtifactsDir "VSSetup\$configuration"
186
if ($ci -and $build) {
187
Check-RequiredVersionBumps
192
if ($ci -and $build) {
200
Write-Host $_.Exception
201
Write-Host $_.ScriptStackTrace