msbuild

Форк
0
/
build.ps1 
166 строк · 5.8 Кб
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

34
# Unset 'Platform' environment variable to avoid unwanted collision in InstallDotNetCore.targets file
35
# some computer has this env var defined (e.g. Some HP)
36
if($env:Platform) {
37
  $env:Platform=""  
38
}
39
function Print-Usage() {
40
  Write-Host "Common settings:"
41
  Write-Host "  -configuration <value>  Build configuration: 'Debug' or 'Release' (short: -c)"
42
  Write-Host "  -platform <value>       Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild"
43
  Write-Host "  -verbosity <value>      Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
44
  Write-Host "  -binaryLog              Output binary log (short: -bl)"
45
  Write-Host "  -help                   Print help and exit"
46
  Write-Host ""
47

48
  Write-Host "Actions:"
49
  Write-Host "  -restore                Restore dependencies (short: -r)"
50
  Write-Host "  -build                  Build solution (short: -b)"
51
  Write-Host "  -rebuild                Rebuild solution"
52
  Write-Host "  -deploy                 Deploy built VSIXes"
53
  Write-Host "  -deployDeps             Deploy dependencies (e.g. VSIXes for integration tests)"
54
  Write-Host "  -test                   Run all unit tests in the solution (short: -t)"
55
  Write-Host "  -integrationTest        Run all integration tests in the solution"
56
  Write-Host "  -performanceTest        Run all performance tests in the solution"
57
  Write-Host "  -pack                   Package build outputs into NuGet packages and Willow components"
58
  Write-Host "  -sign                   Sign build outputs"
59
  Write-Host "  -publish                Publish artifacts (e.g. symbols)"
60
  Write-Host "  -clean                  Clean the solution"
61
  Write-Host ""
62

63
  Write-Host "Advanced settings:"
64
  Write-Host "  -projects <value>       Semi-colon delimited list of sln/proj's to build. Globbing is supported (*.sln)"
65
  Write-Host "  -ci                     Set when running on CI server"
66
  Write-Host "  -excludeCIBinarylog     Don't output binary log (short: -nobl)"
67
  Write-Host "  -prepareMachine         Prepare machine for CI run, clean up processes after build"
68
  Write-Host "  -warnAsError <value>    Sets warnaserror msbuild parameter ('true' or 'false')"
69
  Write-Host "  -msbuildEngine <value>  Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)."
70
  Write-Host "  -excludePrereleaseVS    Set to exclude build engines in prerelease versions of Visual Studio"
71
  Write-Host "  -nativeToolsOnMachine   Sets the native tools on machine environment variable (indicating that the script should use native tools on machine)"
72
  Write-Host ""
73

74
  Write-Host "Command line arguments not listed above are passed thru to msbuild."
75
  Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)."
76
}
77

78
. $PSScriptRoot\tools.ps1
79

80
function InitializeCustomToolset {
81
  if (-not $restore) {
82
    return
83
  }
84

85
  $script = Join-Path $EngRoot 'restore-toolset.ps1'
86

87
  if (Test-Path $script) {
88
    . $script
89
  }
90
}
91

92
function Build {
93
  $toolsetBuildProj = InitializeToolset
94
  InitializeCustomToolset
95

96
  $bl = if ($binaryLog) { '/bl:' + (Join-Path $LogDir 'Build.binlog') } else { '' }
97
  $platformArg = if ($platform) { "/p:Platform=$platform" } else { '' }
98

99
  if ($projects) {
100
    # Re-assign properties to a new variable because PowerShell doesn't let us append properties directly for unclear reasons.
101
    # Explicitly set the type as string[] because otherwise PowerShell would make this char[] if $properties is empty.
102
    [string[]] $msbuildArgs = $properties
103
    
104
    # Resolve relative project paths into full paths 
105
    $projects = ($projects.Split(';').ForEach({Resolve-Path $_}) -join ';')
106
    
107
    $msbuildArgs += "/p:Projects=$projects"
108
    $properties = $msbuildArgs
109
  }
110

111
  MSBuild $toolsetBuildProj `
112
    $bl `
113
    $platformArg `
114
    /p:Configuration=$configuration `
115
    /p:RepoRoot=$RepoRoot `
116
    /p:Restore=$restore `
117
    /p:DeployDeps=$deployDeps `
118
    /p:Build=$build `
119
    /p:Rebuild=$rebuild `
120
    /p:Deploy=$deploy `
121
    /p:Test=$test `
122
    /p:Pack=$pack `
123
    /p:IntegrationTest=$integrationTest `
124
    /p:PerformanceTest=$performanceTest `
125
    /p:Sign=$sign `
126
    /p:Publish=$publish `
127
    @properties
128
}
129

130
try {
131
  if ($clean) {
132
    if (Test-Path $ArtifactsDir) {
133
      Remove-Item -Recurse -Force $ArtifactsDir
134
      Write-Host 'Artifacts directory deleted.'
135
    }
136
    exit 0
137
  }
138

139
  if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) {
140
    Print-Usage
141
    exit 0
142
  }
143

144
  if ($ci) {
145
    if (-not $excludeCIBinarylog) {
146
      $binaryLog = $true
147
    }
148
    $nodeReuse = $false
149
  }
150

151
  if ($nativeToolsOnMachine) {
152
    $env:NativeToolsOnMachine = $true
153
  }
154
  if ($restore) {
155
    InitializeNativeTools
156
  }
157

158
  Build
159
}
160
catch {
161
  Write-Host $_.ScriptStackTrace
162
  Write-PipelineTelemetryError -Category 'InitializeToolset' -Message $_
163
  ExitWithExitCode 1
164
}
165

166
ExitWithExitCode 0
167

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.