1+ [CmdletBinding ()]
12Param (
2- [string ]$Script = " build.cake" ,
3- [string ]$Target = " Default" ,
4- [ValidateSet (" Release" , " Debug" )]
5- [string ]$Configuration = " Release" ,
6- [ValidateSet (" Quiet" , " Minimal" , " Normal" , " Verbose" , " Diagnostic" )]
7- [string ]$Verbosity = " Verbose" ,
8- [switch ]$Experimental ,
9- [switch ]$WhatIf ,
10- [switch ]$Mono ,
11- [switch ]$SkipToolPackageRestore ,
123 [Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
13- [string []]$ScriptArgs
4+ [string []]$BuildArguments
145)
156
16- $PSScriptRoot = split-path - parent $MyInvocation.MyCommand.Definition ;
17- $UseDryRun = " " ;
18- $UseMono = " " ;
19- $TOOLS_DIR = Join-Path $PSScriptRoot " tools"
20- $NUGET_EXE = Join-Path $TOOLS_DIR " nuget.exe"
21- $NUGET_OLD_EXE = Join-Path $TOOLS_DIR " nuget_old.exe"
22- $CAKE_EXE = Join-Path $TOOLS_DIR " Cake/Cake.exe"
23- $NUGET_URL = " https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
24- $NUGET_OLD_URL = " https://dist.nuget.org/win-x86-commandline/v3.5.0/nuget.exe"
7+ Write-Output " PowerShell $ ( $PSVersionTable.PSEdition ) version $ ( $PSVersionTable.PSVersion ) "
258
26- # Should we use experimental build of Roslyn?
27- $UseExperimental = " " ;
28- if ($Experimental.IsPresent ) {
29- $UseExperimental = " --experimental"
30- }
9+ Set-StrictMode - Version 2.0 ; $ErrorActionPreference = " Stop" ; $ConfirmPreference = " None" ; trap { Write-Error $_ - ErrorAction Continue ; exit 1 }
10+ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
3111
32- # Is this a dry run?
33- if ($WhatIf.IsPresent ) {
34- $UseDryRun = " --dryrun"
35- }
12+ # ##########################################################################
13+ # CONFIGURATION
14+ # ##########################################################################
3615
37- # Should we use mono?
38- if ($Mono.IsPresent ) {
39- $UseMono = " --mono"
40- }
16+ $BuildProjectFile = " $PSScriptRoot \nuke\_build.csproj"
17+ $TempDirectory = " $PSScriptRoot \\.nuke\temp"
4118
42- # Try download NuGet.exe if do not exist.
43- if (! (Test-Path $NUGET_EXE )) {
44- (New-Object System.Net.WebClient).DownloadFile($NUGET_URL , $NUGET_EXE )
45- }
19+ $DotNetGlobalFile = " $PSScriptRoot \\global.json"
20+ $DotNetInstallUrl = " https://dot.net/v1/dotnet-install.ps1"
21+ $DotNetChannel = " STS"
4622
47- # Try download NuGet.exe if do not exist.
48- if (! (Test-Path $NUGET_OLD_URL )) {
49- (New-Object System.Net.WebClient).DownloadFile($NUGET_OLD_URL , $NUGET_OLD_EXE )
50- }
23+ $env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
24+ $env: DOTNET_NOLOGO = 1
5125
52- # Make sure NuGet (latest) exists where we expect it.
53- if (! (Test-Path $NUGET_EXE )) {
54- Throw " Could not find nuget.exe"
26+ # ##########################################################################
27+ # EXECUTION
28+ # ##########################################################################
29+
30+ function ExecSafe ([scriptblock ] $cmd ) {
31+ & $cmd
32+ if ($LASTEXITCODE ) { exit $LASTEXITCODE }
5533}
5634
57- # Make sure NuGet (v3.5.0) exists where we expect it.
58- if (! (Test-Path $NUGET_OLD_EXE )) {
59- Throw " Could not find nuget_old.exe"
35+ # If dotnet CLI is installed globally and it matches requested version, use for execution
36+ if ($null -ne (Get-Command " dotnet" - ErrorAction SilentlyContinue) -and `
37+ $ (dotnet -- version) -and $LASTEXITCODE -eq 0 ) {
38+ $env: DOTNET_EXE = (Get-Command " dotnet" ).Path
6039}
40+ else {
41+ # Download install script
42+ $DotNetInstallFile = " $TempDirectory \dotnet-install.ps1"
43+ New-Item - ItemType Directory - Path $TempDirectory - Force | Out-Null
44+ [Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
45+ (New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl , $DotNetInstallFile )
46+
47+ # If global.json exists, load expected version
48+ if (Test-Path $DotNetGlobalFile ) {
49+ $DotNetGlobal = $ (Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json )
50+ if ($DotNetGlobal.PSObject.Properties [" sdk" ] -and $DotNetGlobal.sdk.PSObject.Properties [" version" ]) {
51+ $DotNetVersion = $DotNetGlobal.sdk.version
52+ }
53+ }
6154
62- # Restore tools from NuGet?
63- if (-Not $SkipToolPackageRestore.IsPresent )
64- {
65- Push-Location
66- Set-Location $TOOLS_DIR
67- Invoke-Expression " $NUGET_EXE install -ExcludeVersion"
68- Pop-Location
69- if ($LASTEXITCODE -ne 0 ) {
70- exit $LASTEXITCODE
55+ # Install by channel or version
56+ $DotNetDirectory = " $TempDirectory \dotnet-win"
57+ if (! (Test-Path variable:DotNetVersion)) {
58+ ExecSafe { & powershell $DotNetInstallFile - InstallDir $DotNetDirectory - Channel $DotNetChannel - NoPath }
59+ } else {
60+ ExecSafe { & powershell $DotNetInstallFile - InstallDir $DotNetDirectory - Version $DotNetVersion - NoPath }
7161 }
62+ $env: DOTNET_EXE = " $DotNetDirectory \dotnet.exe"
63+ $env: PATH = " $DotNetDirectory ;$env: PATH "
7264}
7365
74- # Make sure that Cake has been installed.
75- if (! (Test-Path $CAKE_EXE )) {
76- Throw " Could not find Cake.exe"
66+ Write-Output " Microsoft (R) .NET SDK version $ ( & $env: DOTNET_EXE -- version) "
67+
68+ if (Test-Path env:NUKE_ENTERPRISE_TOKEN) {
69+ & $env: DOTNET_EXE nuget remove source " nuke-enterprise" > $null
70+ & $env: DOTNET_EXE nuget add source " https://f.feedz.io/nuke/enterprise/nuget" -- name " nuke-enterprise" -- username " PAT" -- password $env: NUKE_ENTERPRISE_TOKEN > $null
7771}
7872
79- # Start Cake
80- Invoke-Expression " $CAKE_EXE `" $Script `" --target=`" $Target `" --configuration=`" $Configuration `" --verbosity=`" $Verbosity `" $UseMono $UseDryRun $UseExperimental $ScriptArgs "
81- exit $LASTEXITCODE
73+ ExecSafe { & $env: DOTNET_EXE build $BuildProjectFile / nodeReuse:false / p:UseSharedCompilation= false - nologo - clp:NoSummary -- verbosity quiet }
74+ ExecSafe { & $env: DOTNET_EXE run -- project $BuildProjectFile -- no- build -- $BuildArguments }
0 commit comments