Skip to content

Commit 174493e

Browse files
committed
Evolve build.ps1 to work with Nuget 3 or greater
1 parent e42fce0 commit 174493e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

build.ps1

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
$ErrorActionPreference = "Stop"
22
# functions:
33

4-
function IsNugetVersion3($theNugetExe) {
4+
function IsNugetVersion3OrAbove($theNugetExe) {
55
try {
66
$nugetText = . $theNugetExe | Out-String
77
} catch {
88
return false
99
}
10-
[regex]$regex = '^NuGet Version: (.*)\n'
10+
[regex]$regex = '^NuGet Version: (\d)\.(\d).*\n'
1111
$match = $regex.Match($nugetText)
1212
$version = $match.Groups[1].Value
13-
return $version.StartsWith(3)
13+
Write-Host "Nuget major version is $version"
14+
return [System.Convert]::ToInt32($version) -ge 3
1415
}
1516

1617
function Get-Nuget {
1718
if (gcm nuget -ErrorAction SilentlyContinue) {
18-
if (IsNugetVersion3 'nuget') {
19-
$nugetExe = 'nuget'
19+
if (IsNugetVersion3OrAbove 'nuget') {
20+
$script:nugetExe = 'nuget'
2021
} else {
2122
Download-Nuget
22-
$nugetExe = $localNuget
23+
$script:nugetExe = $localNuget
2324
}
2425
} else {
2526
Download-Nuget
26-
$nugetExe = $localNuget
27+
$script:nugetExe = $localNuget
2728
}
2829
}
2930

@@ -33,10 +34,10 @@ function Download-Nuget {
3334
md "$env:TEMP\codecracker\" | Out-Null
3435
}
3536
if (Test-Path $localNuget) {
36-
if (IsNugetVersion3($localNuget)) { return }
37+
if (IsNugetVersion3OrAbove($localNuget)) { return }
3738
}
3839
if (Test-Path $tempNuget) {
39-
if (IsNugetVersion3($tempNuget)) {
40+
if (IsNugetVersion3OrAbove($tempNuget)) {
4041
cp $tempNuget $localNuget
4142
return
4243
}
@@ -48,7 +49,8 @@ function Download-Nuget {
4849
function Import-Psake {
4950
$psakeModule = "$PSScriptRoot\packages\psake.4.5.0\tools\psake.psm1"
5051
if ((Test-Path $psakeModule) -ne $true) {
51-
. "$nugetExe" restore $PSScriptRoot\.nuget\packages.config -SolutionDirectory $PSScriptRoot
52+
Write-Host "Restoring $PSScriptRoot\.nuget with $script:nugetExe"
53+
. "$script:nugetExe" restore $PSScriptRoot\.nuget\packages.config -SolutionDirectory $PSScriptRoot
5254
}
5355
Import-Module $psakeModule -force
5456
}

0 commit comments

Comments
 (0)