Skip to content

Commit be2f67f

Browse files
ASP.NET Push Botunknown
authored andcommitted
⬆️ dnvm.ps1, dnvm.cmd, dnvm.sh
Source: aspnet/dnvm@f5f8e1a
1 parent 43f7c54 commit be2f67f

File tree

2 files changed

+66
-15
lines changed

2 files changed

+66
-15
lines changed

dnvm.ps1

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function _WriteOut {
5959

6060
### Constants
6161
$ProductVersion="1.0.0"
62-
$BuildVersion="beta4-10346"
62+
$BuildVersion="beta4-10347"
6363
$Authors="Microsoft Open Technologies, Inc."
6464

6565
# If the Version hasn't been replaced...
@@ -88,6 +88,8 @@ Set-Variable -Option Constant "OldUserHomes" @("%USERPROFILE%\.kre","%USERPROFIL
8888
Set-Variable -Option Constant "DefaultUserHome" "%USERPROFILE%\$DefaultUserDirectoryName"
8989
Set-Variable -Option Constant "HomeEnvVar" "DNX_HOME"
9090

91+
Set-Variable -Option Constant "RuntimeShortFriendlyName" "DNX"
92+
9193
Set-Variable -Option Constant "AsciiArt" @"
9294
___ _ ___ ____ ___
9395
/ _ \/ |/ / | / / |/ /
@@ -337,7 +339,12 @@ function Write-Alias {
337339
[Parameter(Mandatory=$false)][string]$Architecture,
338340
[Parameter(Mandatory=$false)][string]$Runtime)
339341

340-
$runtimeFullName = Get-RuntimeName $Version $Architecture $Runtime
342+
# If the first character is non-numeric, it's a full runtime name
343+
if(![Char]::IsDigit($Version[0])) {
344+
$runtimeFullName = $Version
345+
} else {
346+
$runtimeFullName = Get-RuntimeName $Version $Architecture $Runtime
347+
}
341348
$aliasFilePath = Join-Path $AliasesDir "$Name.txt"
342349
$action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" }
343350

@@ -453,15 +460,45 @@ function Download-Package(
453460
$url = "$Feed/package/" + (Get-RuntimeId $Architecture $Runtime) + "/" + $Version
454461

455462
_WriteOut "Downloading $runtimeFullName from $feed"
456-
457463
$wc = New-Object System.Net.WebClient
458-
Apply-Proxy $wc -Proxy:$Proxy
459-
_WriteDebug "Downloading $url ..."
460464
try {
461-
$wc.DownloadFile($url, $DestinationFile)
462-
} catch {
463-
$Script:ExitCode = $ExitCodes.NoSuchPackage
464-
throw "Could not find $runtimeFullName.$Version on feed: $Feed"
465+
Apply-Proxy $wc -Proxy:$Proxy
466+
_WriteDebug "Downloading $url ..."
467+
468+
Register-ObjectEvent $wc DownloadProgressChanged -SourceIdentifier WebClient.ProgressChanged -action {
469+
$Global:downloadData = $eventArgs
470+
} | Out-Null
471+
472+
Register-ObjectEvent $wc DownloadFileCompleted -SourceIdentifier WebClient.ProgressComplete -action {
473+
$Global:downloadData = $eventArgs
474+
$Global:downloadCompleted = $true
475+
} | Out-Null
476+
477+
$wc.DownloadFileAsync($url, $DestinationFile)
478+
479+
while(-not $Global:downloadCompleted){
480+
$percent = $Global:downloadData.ProgressPercentage
481+
$totalBytes = $Global:downloadData.TotalBytesToReceive
482+
$receivedBytes = $Global:downloadData.BytesReceived
483+
If ($percent -ne $null) {
484+
Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $url") `
485+
-Status ("Downloaded $($Global:downloadData.BytesReceived) of $($Global:downloadData.TotalBytesToReceive) bytes") `
486+
-PercentComplete $percent -Id 2 -ParentId 1
487+
}
488+
}
489+
490+
if($Global:downloadData.Error){
491+
throw "Unable to download package: {0}" -f $Global:downloadData.Error.Message
492+
}
493+
494+
Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $url") -Id 2 -ParentId 1 -Completed
495+
}
496+
finally {
497+
Remove-Variable downloadData -Scope "Global"
498+
Remove-Variable downloadCompleted -Scope "Global"
499+
Unregister-Event -SourceIdentifier WebClient.ProgressChanged
500+
Unregister-Event -SourceIdentifier WebClient.ProgressComplete
501+
$wc.Dispose()
465502
}
466503
}
467504

@@ -597,7 +634,7 @@ function Ngen-Library(
597634
$ngenCmds += "$ngenExe install $($bin.FullName);"
598635
}
599636

600-
$ngenProc = Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList "-ExecutionPolicy unrestricted & $ngenCmds" -Wait -PassThru
637+
$ngenProc = Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList "-ExecutionPolicy unrestricted & $ngenCmds" -Wait -PassThru -WindowStyle Hidden
601638
}
602639

603640
function Is-Elevated() {
@@ -859,7 +896,7 @@ function dnvm-upgrade {
859896
[Parameter(Mandatory=$false)]
860897
[switch]$Ngen)
861898

862-
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen
899+
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Persistent:$true
863900
}
864901

865902
<#
@@ -883,6 +920,8 @@ function dnvm-upgrade {
883920
Skip generation of native images
884921
.PARAMETER Ngen
885922
For CLR flavor only. Generate native images for runtime libraries on Desktop CLR to improve startup time. This option requires elevated privilege and will be automatically turned on if the script is running in administrative mode. To opt-out in administrative mode, use -NoNative switch.
923+
.PARAMETER Persistent
924+
Make the installed runtime useable across all processes run by the current user
886925
.DESCRIPTION
887926
A proxy can also be specified by using the 'http_proxy' environment variable
888927
@@ -917,7 +956,10 @@ function dnvm-install {
917956
[switch]$NoNative,
918957

919958
[Parameter(Mandatory=$false)]
920-
[switch]$Ngen)
959+
[switch]$Ngen,
960+
961+
[Parameter(Mandatory=$false)]
962+
[switch]$Persistent)
921963

922964
if(!$VersionNuPkgOrAlias) {
923965
_WriteOut "A version, nupkg path, or the string 'latest' must be provided."
@@ -927,6 +969,7 @@ function dnvm-install {
927969
}
928970

929971
if ($VersionNuPkgOrAlias -eq "latest") {
972+
Write-Progress -Activity "Installing runtime" "Determining latest runtime" -Id 1
930973
$VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture
931974
}
932975

@@ -936,6 +979,7 @@ function dnvm-install {
936979
if(!(Test-Path $VersionNuPkgOrAlias)) {
937980
throw "Unable to locate package file: '$VersionNuPkgOrAlias'"
938981
}
982+
Write-Progress -Activity "Installing runtime" "Parsing package file name" -Id 1
939983
$runtimeFullName = [System.IO.Path]::GetFileNameWithoutExtension($VersionNuPkgOrAlias)
940984
$Architecture = Get-PackageArch $runtimeFullName
941985
$Runtime = Get-PackageRuntime $runtimeFullName
@@ -974,14 +1018,17 @@ function dnvm-install {
9741018
New-Item -Type Directory $UnpackFolder | Out-Null
9751019

9761020
if($IsNuPkg) {
1021+
Write-Progress -Activity "Installing runtime" "Copying package" -Id 1
9771022
_WriteDebug "Copying local nupkg $VersionNuPkgOrAlias to $DownloadFile"
9781023
Copy-Item $VersionNuPkgOrAlias $DownloadFile
9791024
} else {
9801025
# Download the package
1026+
Write-Progress -Activity "Installing runtime" "Downloading runtime" -Id 1
9811027
_WriteDebug "Downloading version $VersionNuPkgOrAlias to $DownloadFile"
9821028
Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy
9831029
}
9841030

1031+
Write-Progress -Activity "Installing runtime" "Unpacking runtime" -Id 1
9851032
Unpack-Package $DownloadFile $UnpackFolder
9861033

9871034
New-Item -Type Directory $RuntimeFolder -Force | Out-Null
@@ -991,12 +1038,13 @@ function dnvm-install {
9911038
_WriteDebug "Cleaning temporary directory $UnpackFolder"
9921039
Remove-Item $UnpackFolder -Force | Out-Null
9931040

994-
dnvm-use $PackageVersion -Architecture:$Architecture -Runtime:$Runtime
1041+
dnvm-use $PackageVersion -Architecture:$Architecture -Runtime:$Runtime -Persistent:$Persistent
9951042

9961043
if ($Runtime -eq "clr") {
9971044
if (-not $NoNative) {
9981045
if ((Is-Elevated) -or $Ngen) {
9991046
$runtimeBin = Get-RuntimePath $runtimeFullName
1047+
Write-Progress -Activity "Installing runtime" "Generating runtime native images" -Id 1
10001048
Ngen-Library $runtimeBin $Architecture
10011049
}
10021050
else {
@@ -1010,7 +1058,8 @@ function dnvm-install {
10101058
}
10111059
else {
10121060
_WriteOut "Compiling native images for $runtimeFullName to improve startup performance..."
1013-
Start-Process $CrossGenCommand -Wait
1061+
Write-Progress -Activity "Installing runtime" "Generating runtime native images" -Id 1
1062+
Start-Process $CrossGenCommand -Wait -WindowStyle Hidden
10141063
_WriteOut "Finished native image compilation."
10151064
}
10161065
}
@@ -1023,6 +1072,8 @@ function dnvm-install {
10231072
_WriteDebug "Aliasing installed runtime to '$Alias'"
10241073
dnvm-alias $Alias $PackageVersion -Architecture:$Architecture -Runtime:$Runtime
10251074
}
1075+
1076+
Write-Progress -Activity "Install complete" -Id 1 -Complete
10261077
}
10271078

10281079

dnvm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Source this file from your .bash-profile or script to use
33

44
# "Constants"
5-
_DNVM_BUILDNUMBER="beta4-10346"
5+
_DNVM_BUILDNUMBER="beta4-10347"
66
_DNVM_AUTHORS="Microsoft Open Technologies, Inc."
77
_DNVM_RUNTIME_PACKAGE_NAME="dnx"
88
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"

0 commit comments

Comments
 (0)