Skip to content
This repository was archived by the owner on Dec 18, 2017. It is now read-only.

Commit f5c2fdf

Browse files
committed
Changes to allow dnvm to work on PowerShell 2.0
1 parent 8d184bf commit f5c2fdf

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/dnvm.ps1

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Version 3
1+
#Requires -Version 2
22

33
if (Test-Path env:WEBSITE_SITE_NAME)
44
{
@@ -252,7 +252,7 @@ function Safe-Filecopy {
252252
}
253253

254254
function GetArch($Architecture, $FallBackArch = $DefaultArchitecture) {
255-
if(![String]::IsNullOrWhiteSpace($Architecture)) {
255+
if(![String]::IsNullOrEmpty($Architecture)) {
256256
$Architecture
257257
} elseif($CompatArch) {
258258
$CompatArch
@@ -262,7 +262,7 @@ function GetArch($Architecture, $FallBackArch = $DefaultArchitecture) {
262262
}
263263

264264
function GetRuntime($Runtime) {
265-
if(![String]::IsNullOrWhiteSpace($Runtime)) {
265+
if(![String]::IsNullOrEmpty($Runtime)) {
266266
$Runtime
267267
} else {
268268
$DefaultRuntime
@@ -560,7 +560,7 @@ function Download-Package(
560560
}
561561
}
562562

563-
Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $url") -Id 2 -ParentId 1 -Completed
563+
Write-Progress -Status "Done" -Activity ("Downloading $RuntimeShortFriendlyName from $url") -Id 2 -ParentId 1 -Completed
564564
}
565565
finally {
566566
Remove-Variable downloadData -Scope "Global"
@@ -632,10 +632,10 @@ function Change-Path() {
632632

633633
$newPath = $prependPath
634634
foreach($portion in $existingPaths.Split(';')) {
635-
if(![string]::IsNullOrWhiteSpace($portion)) {
635+
if(![string]::IsNullOrEmpty($portion)) {
636636
$skip = $portion -eq ""
637637
foreach($removePath in $removePaths) {
638-
if(![string]::IsNullOrWhiteSpace($removePath)) {
638+
if(![string]::IsNullOrEmpty($removePath)) {
639639
$removePrefix = if($removePath.EndsWith("\")) { $removePath } else { "$removePath\" }
640640

641641
if ($removePath -and (($portion -eq $removePath) -or ($portion.StartsWith($removePrefix)))) {
@@ -645,7 +645,7 @@ function Change-Path() {
645645
}
646646
}
647647
if (!$skip) {
648-
if(![String]::IsNullOrWhiteSpace($newPath)) {
648+
if(![String]::IsNullOrEmpty($newPath)) {
649649
$newPath += ";"
650650
}
651651
$newPath += $portion
@@ -752,7 +752,7 @@ function dnvm-help {
752752
return
753753
}
754754
$help = Get-Help "dnvm-$Command"
755-
if($PassThru) {
755+
if($PassThru -Or $Host.Version.Major -lt 3) {
756756
$help
757757
} else {
758758
_WriteOut -ForegroundColor $ColorScheme.Help_Header "$CommandName $Command"
@@ -1084,7 +1084,7 @@ function dnvm-install {
10841084
}
10851085

10861086
if ($VersionNuPkgOrAlias -eq "latest") {
1087-
Write-Progress -Activity "Installing runtime" "Determining latest runtime" -Id 1
1087+
Write-Progress -Status "Determining Latest Runtime" -Activity "Installing runtime" -Id 1
10881088
$VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture -Feed:$selectedFeed
10891089
}
10901090

@@ -1094,7 +1094,7 @@ function dnvm-install {
10941094
if(!(Test-Path $VersionNuPkgOrAlias)) {
10951095
throw "Unable to locate package file: '$VersionNuPkgOrAlias'"
10961096
}
1097-
Write-Progress -Activity "Installing runtime" "Parsing package file name" -Id 1
1097+
Write-Progress -Activity "Installing runtime" -Status "Parsing package file name" -Id 1
10981098
$runtimeFullName = [System.IO.Path]::GetFileNameWithoutExtension($VersionNuPkgOrAlias)
10991099
$Architecture = Get-PackageArch $runtimeFullName
11001100
$Runtime = Get-PackageRuntime $runtimeFullName
@@ -1134,18 +1134,18 @@ function dnvm-install {
11341134
New-Item -Type Directory $UnpackFolder | Out-Null
11351135

11361136
if($IsNuPkg) {
1137-
Write-Progress -Activity "Installing runtime" "Copying package" -Id 1
1137+
Write-Progress -Activity "Installing runtime" -Status "Copying package" -Id 1
11381138
_WriteDebug "Copying local nupkg $VersionNuPkgOrAlias to $DownloadFile"
11391139
Copy-Item $VersionNuPkgOrAlias $DownloadFile
11401140
} else {
11411141
# Download the package
1142-
Write-Progress -Activity "Installing runtime" "Downloading runtime" -Id 1
1142+
Write-Progress -Activity "Installing runtime" -Status "Downloading runtime" -Id 1
11431143
_WriteDebug "Downloading version $VersionNuPkgOrAlias to $DownloadFile"
11441144

11451145
Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy -Feed:$selectedFeed
11461146
}
11471147

1148-
Write-Progress -Activity "Installing runtime" "Unpacking runtime" -Id 1
1148+
Write-Progress -Activity "Installing runtime" -Status "Unpacking runtime" -Id 1
11491149
Unpack-Package $DownloadFile $UnpackFolder
11501150

11511151
if(Test-Path $RuntimeFolder) {
@@ -1164,7 +1164,7 @@ function dnvm-install {
11641164
if (-not $NoNative) {
11651165
if ((Is-Elevated) -or $Ngen) {
11661166
$runtimeBin = Get-RuntimePath $runtimeFullName
1167-
Write-Progress -Activity "Installing runtime" "Generating runtime native images" -Id 1
1167+
Write-Progress -Activity "Installing runtime" -Status "Generating runtime native images" -Id 1
11681168
Ngen-Library $runtimeBin $Architecture
11691169
}
11701170
else {
@@ -1178,7 +1178,7 @@ function dnvm-install {
11781178
}
11791179
else {
11801180
_WriteOut "Compiling native images for $runtimeFullName to improve startup performance..."
1181-
Write-Progress -Activity "Installing runtime" "Generating runtime native images" -Id 1
1181+
Write-Progress -Activity "Installing runtime" -Status "Generating runtime native images" -Id 1
11821182
if ($DebugPreference -eq 'SilentlyContinue') {
11831183
Start-Process $CrossGenCommand -Wait -WindowStyle Hidden
11841184
}
@@ -1198,7 +1198,7 @@ function dnvm-install {
11981198
dnvm-alias $Alias $PackageVersion -Architecture:$Architecture -Runtime:$Runtime
11991199
}
12001200

1201-
Write-Progress -Activity "Install complete" -Id 1 -Complete
1201+
Write-Progress -Status "Done" -Activity "Install complete" -Id 1 -Complete
12021202
}
12031203

12041204

@@ -1431,7 +1431,11 @@ if(!$cmd) {
14311431
try {
14321432
if(Get-Command -Name "$CommandPrefix$cmd" -ErrorAction SilentlyContinue) {
14331433
_WriteDebug "& dnvm-$cmd $cmdargs"
1434-
& "dnvm-$cmd" @cmdargs
1434+
if($host.Version.Major -lt 3) {
1435+
Invoke-Command ([ScriptBlock]::Create("dnvm-$cmd $cmdargs"))
1436+
} else {
1437+
& "dnvm-$cmd" @cmdargs
1438+
}
14351439
}
14361440
else {
14371441
_WriteOut "Unknown command: '$cmd'"

0 commit comments

Comments
 (0)