1+ [CmdletBinding ()]
2+ Param (
3+ [Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
4+ [string []]$BuildArguments
5+ )
6+
7+ Write-Output " PowerShell $ ( $PSVersionTable.PSEdition ) version $ ( $PSVersionTable.PSVersion ) "
8+
9+ Set-StrictMode - Version 2.0 ; $ErrorActionPreference = " Stop" ; $ConfirmPreference = " None" ; trap { Write-Error $_ - ErrorAction Continue ; exit 1 }
10+
11+ # ##########################################################################
12+ # CONFIGURATION
13+ # ##########################################################################
14+
15+ $SolutionDirectory = Split-Path $PSScriptRoot - Parent
16+ $BuildProjectFile = " $SolutionDirectory \Build\Build.csproj"
17+ $TempDirectory = " $SolutionDirectory \.nuke\temp"
18+
19+ $DotNetGlobalFile = " $SolutionDirectory \global.json"
20+ $DotNetInstallUrl = " https://dot.net/v1/dotnet-install.ps1"
21+ $DotNetChannel = " Current"
22+
23+ $env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
24+ $env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
25+ $env: DOTNET_MULTILEVEL_LOOKUP = 0
26+
27+ # ##########################################################################
28+ # EXECUTION
29+ # ##########################################################################
30+
31+ function ExecSafe ([scriptblock ] $cmd ) {
32+ & $cmd
33+ if ($LASTEXITCODE ) { exit $LASTEXITCODE }
34+ }
35+
36+ # If dotnet CLI is installed globally and it matches requested version, use for execution
37+ if ($null -ne (Get-Command " dotnet" - ErrorAction SilentlyContinue) -and `
38+ $ (dotnet -- version) -and $LASTEXITCODE -eq 0 ) {
39+ $env: DOTNET_EXE = (Get-Command " dotnet" ).Path
40+ }
41+ else {
42+ # Download install script
43+ $DotNetInstallFile = " $TempDirectory \dotnet-install.ps1"
44+ New-Item - ItemType Directory - Path $TempDirectory - Force | Out-Null
45+ [Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
46+ (New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl , $DotNetInstallFile )
47+
48+ # If global.json exists, load expected version
49+ if (Test-Path $DotNetGlobalFile ) {
50+ $DotNetGlobal = $ (Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json )
51+ if ($DotNetGlobal.PSObject.Properties [" sdk" ] -and $DotNetGlobal.sdk.PSObject.Properties [" version" ]) {
52+ $DotNetVersion = $DotNetGlobal.sdk.version
53+ }
54+ }
55+
56+ # Install by channel or version
57+ $DotNetDirectory = " $TempDirectory \dotnet-win"
58+ if (! (Test-Path variable:DotNetVersion)) {
59+ ExecSafe { & powershell $DotNetInstallFile - InstallDir $DotNetDirectory - Channel $DotNetChannel - NoPath }
60+ } else {
61+ ExecSafe { & powershell $DotNetInstallFile - InstallDir $DotNetDirectory - Version $DotNetVersion - NoPath }
62+ }
63+ $env: DOTNET_EXE = " $DotNetDirectory \dotnet.exe"
64+ }
65+
66+ Write-Output " Microsoft (R) .NET Core SDK version $ ( & $env: DOTNET_EXE -- version) "
67+
68+ ExecSafe { & $env: DOTNET_EXE build $BuildProjectFile / nodeReuse:false / p:UseSharedCompilation= false - nologo - clp:NoSummary -- verbosity quiet }
69+ ExecSafe { & $env: DOTNET_EXE run -- project $BuildProjectFile -- no- build -- $BuildArguments }
0 commit comments