update dnvm

fixes #195
This commit is contained in:
anurse 2015-03-30 11:30:59 -07:00
parent 3bb43e121b
commit 9e872c3721
2 changed files with 114 additions and 40 deletions

View File

@ -59,7 +59,7 @@ function _WriteOut {
### Constants ### Constants
$ProductVersion="1.0.0" $ProductVersion="1.0.0"
$BuildVersion="beta4-10345" $BuildVersion="beta4-10351"
$Authors="Microsoft Open Technologies, Inc." $Authors="Microsoft Open Technologies, Inc."
# If the Version hasn't been replaced... # If the Version hasn't been replaced...
@ -76,7 +76,7 @@ Set-Variable -Option Constant "CommandFriendlyName" ".NET Version Manager"
Set-Variable -Option Constant "DefaultUserDirectoryName" ".dnx" Set-Variable -Option Constant "DefaultUserDirectoryName" ".dnx"
Set-Variable -Option Constant "OldUserDirectoryNames" @(".kre", ".k") Set-Variable -Option Constant "OldUserDirectoryNames" @(".kre", ".k")
Set-Variable -Option Constant "RuntimePackageName" "dnx" Set-Variable -Option Constant "RuntimePackageName" "dnx"
Set-Variable -Option Constant "DefaultFeed" "https://www.myget.org/F/aspnetvnext/api/v2" Set-Variable -Option Constant "DefaultFeed" "https://www.myget.org/F/aspnetrelease/api/v2"
Set-Variable -Option Constant "CrossGenCommand" "k-crossgen" Set-Variable -Option Constant "CrossGenCommand" "k-crossgen"
Set-Variable -Option Constant "CommandPrefix" "dnvm-" Set-Variable -Option Constant "CommandPrefix" "dnvm-"
Set-Variable -Option Constant "DefaultArchitecture" "x86" Set-Variable -Option Constant "DefaultArchitecture" "x86"
@ -88,6 +88,8 @@ Set-Variable -Option Constant "OldUserHomes" @("%USERPROFILE%\.kre","%USERPROFIL
Set-Variable -Option Constant "DefaultUserHome" "%USERPROFILE%\$DefaultUserDirectoryName" Set-Variable -Option Constant "DefaultUserHome" "%USERPROFILE%\$DefaultUserDirectoryName"
Set-Variable -Option Constant "HomeEnvVar" "DNX_HOME" Set-Variable -Option Constant "HomeEnvVar" "DNX_HOME"
Set-Variable -Option Constant "RuntimeShortFriendlyName" "DNX"
Set-Variable -Option Constant "AsciiArt" @" Set-Variable -Option Constant "AsciiArt" @"
___ _ ___ ____ ___ ___ _ ___ ____ ___
/ _ \/ |/ / | / / |/ / / _ \/ |/ / | / / |/ /
@ -337,7 +339,12 @@ function Write-Alias {
[Parameter(Mandatory=$false)][string]$Architecture, [Parameter(Mandatory=$false)][string]$Architecture,
[Parameter(Mandatory=$false)][string]$Runtime) [Parameter(Mandatory=$false)][string]$Runtime)
$runtimeFullName = Get-RuntimeName $Version $Architecture $Runtime # If the first character is non-numeric, it's a full runtime name
if(![Char]::IsDigit($Version[0])) {
$runtimeFullName = $Version
} else {
$runtimeFullName = Get-RuntimeName $Version $Architecture $Runtime
}
$aliasFilePath = Join-Path $AliasesDir "$Name.txt" $aliasFilePath = Join-Path $AliasesDir "$Name.txt"
$action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" } $action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" }
@ -453,15 +460,45 @@ function Download-Package(
$url = "$Feed/package/" + (Get-RuntimeId $Architecture $Runtime) + "/" + $Version $url = "$Feed/package/" + (Get-RuntimeId $Architecture $Runtime) + "/" + $Version
_WriteOut "Downloading $runtimeFullName from $feed" _WriteOut "Downloading $runtimeFullName from $feed"
$wc = New-Object System.Net.WebClient $wc = New-Object System.Net.WebClient
Apply-Proxy $wc -Proxy:$Proxy
_WriteDebug "Downloading $url ..."
try { try {
$wc.DownloadFile($url, $DestinationFile) Apply-Proxy $wc -Proxy:$Proxy
} catch { _WriteDebug "Downloading $url ..."
$Script:ExitCode = $ExitCodes.NoSuchPackage
throw "Could not find $runtimeFullName.$Version on feed: $Feed" Register-ObjectEvent $wc DownloadProgressChanged -SourceIdentifier WebClient.ProgressChanged -action {
$Global:downloadData = $eventArgs
} | Out-Null
Register-ObjectEvent $wc DownloadFileCompleted -SourceIdentifier WebClient.ProgressComplete -action {
$Global:downloadData = $eventArgs
$Global:downloadCompleted = $true
} | Out-Null
$wc.DownloadFileAsync($url, $DestinationFile)
while(-not $Global:downloadCompleted){
$percent = $Global:downloadData.ProgressPercentage
$totalBytes = $Global:downloadData.TotalBytesToReceive
$receivedBytes = $Global:downloadData.BytesReceived
If ($percent -ne $null) {
Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $url") `
-Status ("Downloaded $($Global:downloadData.BytesReceived) of $($Global:downloadData.TotalBytesToReceive) bytes") `
-PercentComplete $percent -Id 2 -ParentId 1
}
}
if($Global:downloadData.Error){
throw "Unable to download package: {0}" -f $Global:downloadData.Error.Message
}
Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $url") -Id 2 -ParentId 1 -Completed
}
finally {
Remove-Variable downloadData -Scope "Global"
Remove-Variable downloadCompleted -Scope "Global"
Unregister-Event -SourceIdentifier WebClient.ProgressChanged
Unregister-Event -SourceIdentifier WebClient.ProgressComplete
$wc.Dispose()
} }
} }
@ -474,7 +511,7 @@ function Unpack-Package([string]$DownloadFile, [string]$UnpackFolder) {
try { try {
# Shell will not recognize nupkg as a zip and throw, so rename it to zip # Shell will not recognize nupkg as a zip and throw, so rename it to zip
$runtimeZip = [System.IO.Path]::ChangeExtension($DownloadFile, "zip") $runtimeZip = [System.IO.Path]::ChangeExtension($DownloadFile, "zip")
Rename-Item $runtimeFile $runtimeZip Rename-Item $DownloadFile $runtimeZip
# Use the shell to uncompress the nupkg # Use the shell to uncompress the nupkg
$shell_app=new-object -com shell.application $shell_app=new-object -com shell.application
$zip_file = $shell_app.namespace($runtimeZip) $zip_file = $shell_app.namespace($runtimeZip)
@ -597,7 +634,7 @@ function Ngen-Library(
$ngenCmds += "$ngenExe install $($bin.FullName);" $ngenCmds += "$ngenExe install $($bin.FullName);"
} }
$ngenProc = Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList "-ExecutionPolicy unrestricted & $ngenCmds" -Wait -PassThru $ngenProc = Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList "-ExecutionPolicy unrestricted & $ngenCmds" -Wait -PassThru -WindowStyle Hidden
} }
function Is-Elevated() { function Is-Elevated() {
@ -859,7 +896,7 @@ function dnvm-upgrade {
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[switch]$Ngen) [switch]$Ngen)
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Persistent:$true
} }
<# <#
@ -883,6 +920,8 @@ function dnvm-upgrade {
Skip generation of native images Skip generation of native images
.PARAMETER Ngen .PARAMETER Ngen
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. 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.
.PARAMETER Persistent
Make the installed runtime useable across all processes run by the current user
.DESCRIPTION .DESCRIPTION
A proxy can also be specified by using the 'http_proxy' environment variable A proxy can also be specified by using the 'http_proxy' environment variable
@ -917,7 +956,10 @@ function dnvm-install {
[switch]$NoNative, [switch]$NoNative,
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[switch]$Ngen) [switch]$Ngen,
[Parameter(Mandatory=$false)]
[switch]$Persistent)
if(!$VersionNuPkgOrAlias) { if(!$VersionNuPkgOrAlias) {
_WriteOut "A version, nupkg path, or the string 'latest' must be provided." _WriteOut "A version, nupkg path, or the string 'latest' must be provided."
@ -927,6 +969,7 @@ function dnvm-install {
} }
if ($VersionNuPkgOrAlias -eq "latest") { if ($VersionNuPkgOrAlias -eq "latest") {
Write-Progress -Activity "Installing runtime" "Determining latest runtime" -Id 1
$VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture $VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture
} }
@ -936,6 +979,7 @@ function dnvm-install {
if(!(Test-Path $VersionNuPkgOrAlias)) { if(!(Test-Path $VersionNuPkgOrAlias)) {
throw "Unable to locate package file: '$VersionNuPkgOrAlias'" throw "Unable to locate package file: '$VersionNuPkgOrAlias'"
} }
Write-Progress -Activity "Installing runtime" "Parsing package file name" -Id 1
$runtimeFullName = [System.IO.Path]::GetFileNameWithoutExtension($VersionNuPkgOrAlias) $runtimeFullName = [System.IO.Path]::GetFileNameWithoutExtension($VersionNuPkgOrAlias)
$Architecture = Get-PackageArch $runtimeFullName $Architecture = Get-PackageArch $runtimeFullName
$Runtime = Get-PackageRuntime $runtimeFullName $Runtime = Get-PackageRuntime $runtimeFullName
@ -974,14 +1018,17 @@ function dnvm-install {
New-Item -Type Directory $UnpackFolder | Out-Null New-Item -Type Directory $UnpackFolder | Out-Null
if($IsNuPkg) { if($IsNuPkg) {
Write-Progress -Activity "Installing runtime" "Copying package" -Id 1
_WriteDebug "Copying local nupkg $VersionNuPkgOrAlias to $DownloadFile" _WriteDebug "Copying local nupkg $VersionNuPkgOrAlias to $DownloadFile"
Copy-Item $VersionNuPkgOrAlias $DownloadFile Copy-Item $VersionNuPkgOrAlias $DownloadFile
} else { } else {
# Download the package # Download the package
Write-Progress -Activity "Installing runtime" "Downloading runtime" -Id 1
_WriteDebug "Downloading version $VersionNuPkgOrAlias to $DownloadFile" _WriteDebug "Downloading version $VersionNuPkgOrAlias to $DownloadFile"
Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy
} }
Write-Progress -Activity "Installing runtime" "Unpacking runtime" -Id 1
Unpack-Package $DownloadFile $UnpackFolder Unpack-Package $DownloadFile $UnpackFolder
New-Item -Type Directory $RuntimeFolder -Force | Out-Null New-Item -Type Directory $RuntimeFolder -Force | Out-Null
@ -991,12 +1038,13 @@ function dnvm-install {
_WriteDebug "Cleaning temporary directory $UnpackFolder" _WriteDebug "Cleaning temporary directory $UnpackFolder"
Remove-Item $UnpackFolder -Force | Out-Null Remove-Item $UnpackFolder -Force | Out-Null
dnvm-use $PackageVersion -Architecture:$Architecture -Runtime:$Runtime dnvm-use $PackageVersion -Architecture:$Architecture -Runtime:$Runtime -Persistent:$Persistent
if ($Runtime -eq "clr") { if ($Runtime -eq "clr") {
if (-not $NoNative) { if (-not $NoNative) {
if ((Is-Elevated) -or $Ngen) { if ((Is-Elevated) -or $Ngen) {
$runtimeBin = Get-RuntimePath $runtimeFullName $runtimeBin = Get-RuntimePath $runtimeFullName
Write-Progress -Activity "Installing runtime" "Generating runtime native images" -Id 1
Ngen-Library $runtimeBin $Architecture Ngen-Library $runtimeBin $Architecture
} }
else { else {
@ -1006,12 +1054,18 @@ function dnvm-install {
} }
elseif ($Runtime -eq "coreclr") { elseif ($Runtime -eq "coreclr") {
if ($NoNative) { if ($NoNative) {
_WriteOut "Skipping native image compilation." _WriteOut "Skipping native image compilation."
} }
else { else {
_WriteOut "Compiling native images for $runtimeFullName to improve startup performance..." _WriteOut "Compiling native images for $runtimeFullName to improve startup performance..."
Start-Process $CrossGenCommand -Wait Write-Progress -Activity "Installing runtime" "Generating runtime native images" -Id 1
_WriteOut "Finished native image compilation." if ($DebugPreference -eq 'SilentlyContinue') {
Start-Process $CrossGenCommand -Wait -WindowStyle Hidden
}
else {
Start-Process $CrossGenCommand -Wait -NoNewWindow
}
_WriteOut "Finished native image compilation."
} }
} }
else { else {
@ -1023,6 +1077,8 @@ function dnvm-install {
_WriteDebug "Aliasing installed runtime to '$Alias'" _WriteDebug "Aliasing installed runtime to '$Alias'"
dnvm-alias $Alias $PackageVersion -Architecture:$Architecture -Runtime:$Runtime dnvm-alias $Alias $PackageVersion -Architecture:$Architecture -Runtime:$Runtime
} }
Write-Progress -Activity "Install complete" -Id 1 -Complete
} }
@ -1122,6 +1178,40 @@ function dnvm-name {
Get-RuntimeName $VersionOrAlias $Architecture $Runtime Get-RuntimeName $VersionOrAlias $Architecture $Runtime
} }
# Checks if a specified file exists in the destination folder and if not, copies the file
# to the destination folder.
function Safe-Filecopy {
param(
[Parameter(Mandatory=$true, Position=0)] $Filename,
[Parameter(Mandatory=$true, Position=1)] $SourceFolder,
[Parameter(Mandatory=$true, Position=2)] $DestinationFolder)
# Make sure the destination folder is created if it doesn't already exist.
if(!(Test-Path $DestinationFolder)) {
_WriteOut "Creating destination folder '$DestinationFolder' ... "
New-Item -Type Directory $Destination | Out-Null
}
$sourceFilePath = Join-Path $SourceFolder $Filename
$destFilePath = Join-Path $DestinationFolder $Filename
if(Test-Path $sourceFilePath) {
_WriteOut "Installing '$Filename' to '$DestinationFolder' ... "
if (Test-Path $destFilePath) {
_WriteOut " Skipping: file already exists" -ForegroundColor Yellow
}
else {
Copy-Item $sourceFilePath $destFilePath -Force
}
}
else {
_WriteOut "WARNING: Unable to install: Could not find '$Filename' in '$SourceFolder'. "
}
}
<# <#
.SYNOPSIS .SYNOPSIS
Installs the version manager into your User profile directory Installs the version manager into your User profile directory
@ -1140,28 +1230,12 @@ function dnvm-setup {
$ScriptFolder = Split-Path -Parent $ScriptPath $ScriptFolder = Split-Path -Parent $ScriptPath
if(!(Test-Path $Destination)) { # Copy script files (if necessary):
New-Item -Type Directory $Destination | Out-Null Safe-Filecopy "$CommandName.ps1" $ScriptFolder $Destination
} Safe-Filecopy "$CommandName.cmd" $ScriptFolder $Destination
$ps1Command = Join-Path $ScriptFolder "$CommandName.ps1"
if(Test-Path $ps1Command) {
_WriteOut "Installing '$CommandName.ps1' to '$Destination' ..."
Copy-Item $ps1Command $Destination -Force
} else {
_WriteOut "WARNING: Could not find '$CommandName.ps1' in '$ScriptFolder'. Unable to install!"
}
$cmdCommand = Join-Path $ScriptFolder "$CommandName.cmd"
if(Test-Path $cmdCommand) {
_WriteOut "Installing '$CommandName.cmd' to '$Destination' ..."
Copy-Item $cmdCommand $Destination -Force
} else {
_WriteOut "WARNING: Could not find '$CommandName.cmd' in '$ScriptFolder'. Unable to install!"
}
# Configure Environment Variables # Configure Environment Variables
# Also, clean old user home values if present # Also, clean old user home values if present
# We'll be removing any existing homes, both # We'll be removing any existing homes, both
$PathsToRemove = @( $PathsToRemove = @(
"%USERPROFILE%\$DefaultUserDirectoryName", "%USERPROFILE%\$DefaultUserDirectoryName",

View File

@ -2,7 +2,7 @@
# Source this file from your .bash-profile or script to use # Source this file from your .bash-profile or script to use
# "Constants" # "Constants"
_DNVM_BUILDNUMBER="beta4-10345" _DNVM_BUILDNUMBER="beta4-10351"
_DNVM_AUTHORS="Microsoft Open Technologies, Inc." _DNVM_AUTHORS="Microsoft Open Technologies, Inc."
_DNVM_RUNTIME_PACKAGE_NAME="dnx" _DNVM_RUNTIME_PACKAGE_NAME="dnx"
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment" _DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"
@ -10,7 +10,7 @@ _DNVM_RUNTIME_SHORT_NAME="DNX"
_DNVM_RUNTIME_FOLDER_NAME=".dnx" _DNVM_RUNTIME_FOLDER_NAME=".dnx"
_DNVM_COMMAND_NAME="dnvm" _DNVM_COMMAND_NAME="dnvm"
_DNVM_VERSION_MANAGER_NAME=".NET Version Manager" _DNVM_VERSION_MANAGER_NAME=".NET Version Manager"
_DNVM_DEFAULT_FEED="https://www.myget.org/F/aspnetvnext/api/v2" _DNVM_DEFAULT_FEED="https://www.myget.org/F/aspnetrelease/api/v2"
_DNVM_HOME_VAR_NAME="DNX_HOME" _DNVM_HOME_VAR_NAME="DNX_HOME"
[ "$_DNVM_BUILDNUMBER" = "{{*" ] && _DNVM_BUILDNUMBER="HEAD" [ "$_DNVM_BUILDNUMBER" = "{{*" ] && _DNVM_BUILDNUMBER="HEAD"