1
+ [CmdletBinding ()]
1
2
Param (
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 ,
12
3
[Parameter (Position = 0 , Mandatory = $false , ValueFromRemainingArguments = $true )]
13
- [string []]$ScriptArgs
4
+ [string []]$BuildArguments
14
5
)
15
6
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 ) "
25
8
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
31
11
32
- # Is this a dry run?
33
- if ($WhatIf.IsPresent ) {
34
- $UseDryRun = " --dryrun"
35
- }
12
+ # ##########################################################################
13
+ # CONFIGURATION
14
+ # ##########################################################################
36
15
37
- # Should we use mono?
38
- if ($Mono.IsPresent ) {
39
- $UseMono = " --mono"
40
- }
16
+ $BuildProjectFile = " $PSScriptRoot \nuke\_build.csproj"
17
+ $TempDirectory = " $PSScriptRoot \\.nuke\temp"
41
18
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 = " Current"
46
22
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_SKIP_FIRST_TIME_EXPERIENCE = 1
24
+ $env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
25
+ $env: DOTNET_MULTILEVEL_LOOKUP = 0
51
26
52
- # Make sure NuGet (latest) exists where we expect it.
53
- if (! (Test-Path $NUGET_EXE )) {
54
- Throw " Could not find nuget.exe"
27
+ # ##########################################################################
28
+ # EXECUTION
29
+ # ##########################################################################
30
+
31
+ function ExecSafe ([scriptblock ] $cmd ) {
32
+ & $cmd
33
+ if ($LASTEXITCODE ) { exit $LASTEXITCODE }
55
34
}
56
35
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"
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
60
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 )
61
47
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
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
+ }
71
54
}
72
- }
73
55
74
- # Make sure that Cake has been installed.
75
- if (! (Test-Path $CAKE_EXE )) {
76
- Throw " Could not find Cake.exe"
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"
77
64
}
78
65
79
- # Start Cake
80
- Invoke-Expression " $CAKE_EXE `" $Script `" --target=`" $Target `" --configuration=`" $Configuration `" --verbosity=`" $Verbosity `" $UseMono $UseDryRun $UseExperimental $ScriptArgs "
81
- exit $LASTEXITCODE
66
+ Write-Output " Microsoft (R) .NET 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