[master] Update dependencies from dotnet/arcade dotnet/core-setup dotnet/corefx ...
[mono-project.git] / eng / common / build.ps1
blob55dff3320442649fc187af9eec1b95cf6727ec23
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
29 . $PSScriptRoot\tools.ps1
31 function Print-Usage() {
32 Write-Host "Common settings:"
33 Write-Host " -configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
34 Write-Host " -platform <value> Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild"
35 Write-Host " -verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
36 Write-Host " -binaryLog Output binary log (short: -bl)"
37 Write-Host " -help Print help and exit"
38 Write-Host ""
40 Write-Host "Actions:"
41 Write-Host " -restore Restore dependencies (short: -r)"
42 Write-Host " -build Build solution (short: -b)"
43 Write-Host " -rebuild Rebuild solution"
44 Write-Host " -deploy Deploy built VSIXes"
45 Write-Host " -deployDeps Deploy dependencies (e.g. VSIXes for integration tests)"
46 Write-Host " -test Run all unit tests in the solution (short: -t)"
47 Write-Host " -integrationTest Run all integration tests in the solution"
48 Write-Host " -performanceTest Run all performance tests in the solution"
49 Write-Host " -pack Package build outputs into NuGet packages and Willow components"
50 Write-Host " -sign Sign build outputs"
51 Write-Host " -publish Publish artifacts (e.g. symbols)"
52 Write-Host " -clean Clean the solution"
53 Write-Host ""
55 Write-Host "Advanced settings:"
56 Write-Host " -projects <value> Semi-colon delimited list of sln/proj's to build. Globbing is supported (*.sln)"
57 Write-Host " -ci Set when running on CI server"
58 Write-Host " -prepareMachine Prepare machine for CI run, clean up processes after build"
59 Write-Host " -warnAsError <value> Sets warnaserror msbuild parameter ('true' or 'false')"
60 Write-Host " -msbuildEngine <value> Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)."
61 Write-Host ""
63 Write-Host "Command line arguments not listed above are passed thru to msbuild."
64 Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)."
67 function InitializeCustomToolset {
68 if (-not $restore) {
69 return
72 $script = Join-Path $EngRoot "restore-toolset.ps1"
74 if (Test-Path $script) {
75 . $script
79 function Build {
80 $toolsetBuildProj = InitializeToolset
81 InitializeCustomToolset
83 $bl = if ($binaryLog) { "/bl:" + (Join-Path $LogDir "Build.binlog") } else { "" }
84 $platformArg = if ($platform) { "/p:Platform=$platform" } else { "" }
86 if ($projects) {
87 # Re-assign properties to a new variable because PowerShell doesn't let us append properties directly for unclear reasons.
88 # Explicitly set the type as string[] because otherwise PowerShell would make this char[] if $properties is empty.
89 [string[]] $msbuildArgs = $properties
91 # Resolve relative project paths into full paths
92 $projects = ($projects.Split(';').ForEach({Resolve-Path $_}) -join ';')
94 $msbuildArgs += "/p:Projects=$projects"
95 $properties = $msbuildArgs
98 MSBuild $toolsetBuildProj `
99 $bl `
100 $platformArg `
101 /p:Configuration=$configuration `
102 /p:RepoRoot=$RepoRoot `
103 /p:Restore=$restore `
104 /p:DeployDeps=$deployDeps `
105 /p:Build=$build `
106 /p:Rebuild=$rebuild `
107 /p:Deploy=$deploy `
108 /p:Test=$test `
109 /p:Pack=$pack `
110 /p:IntegrationTest=$integrationTest `
111 /p:PerformanceTest=$performanceTest `
112 /p:Sign=$sign `
113 /p:Publish=$publish `
114 @properties
117 if ($clean) {
118 if(Test-Path $ArtifactsDir) {
119 Remove-Item -Recurse -Force $ArtifactsDir
120 Write-Host "Artifacts directory deleted."
122 exit 0
125 try {
126 if ($help -or (($null -ne $properties) -and ($properties.Contains("/help") -or $properties.Contains("/?")))) {
127 Print-Usage
128 exit 0
131 if ($ci) {
132 $binaryLog = $true
133 $nodeReuse = $false
136 if ($restore) {
137 InitializeNativeTools
140 Build
142 catch {
143 Write-Host $_.ScriptStackTrace
144 Write-PipelineTelemetryError -Category "InitializeToolset" -Message $_
145 ExitWithExitCode 1
148 ExitWithExitCode 0