parent
3bb43e121b
commit
9e872c3721
150
build/dnvm.ps1
150
build/dnvm.ps1
|
|
@ -59,7 +59,7 @@ function _WriteOut {
|
|||
|
||||
### Constants
|
||||
$ProductVersion="1.0.0"
|
||||
$BuildVersion="beta4-10345"
|
||||
$BuildVersion="beta4-10351"
|
||||
$Authors="Microsoft Open Technologies, Inc."
|
||||
|
||||
# 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 "OldUserDirectoryNames" @(".kre", ".k")
|
||||
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 "CommandPrefix" "dnvm-"
|
||||
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 "HomeEnvVar" "DNX_HOME"
|
||||
|
||||
Set-Variable -Option Constant "RuntimeShortFriendlyName" "DNX"
|
||||
|
||||
Set-Variable -Option Constant "AsciiArt" @"
|
||||
___ _ ___ ____ ___
|
||||
/ _ \/ |/ / | / / |/ /
|
||||
|
|
@ -337,7 +339,12 @@ function Write-Alias {
|
|||
[Parameter(Mandatory=$false)][string]$Architecture,
|
||||
[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"
|
||||
$action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" }
|
||||
|
||||
|
|
@ -453,15 +460,45 @@ function Download-Package(
|
|||
$url = "$Feed/package/" + (Get-RuntimeId $Architecture $Runtime) + "/" + $Version
|
||||
|
||||
_WriteOut "Downloading $runtimeFullName from $feed"
|
||||
|
||||
$wc = New-Object System.Net.WebClient
|
||||
Apply-Proxy $wc -Proxy:$Proxy
|
||||
_WriteDebug "Downloading $url ..."
|
||||
try {
|
||||
$wc.DownloadFile($url, $DestinationFile)
|
||||
} catch {
|
||||
$Script:ExitCode = $ExitCodes.NoSuchPackage
|
||||
throw "Could not find $runtimeFullName.$Version on feed: $Feed"
|
||||
Apply-Proxy $wc -Proxy:$Proxy
|
||||
_WriteDebug "Downloading $url ..."
|
||||
|
||||
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 {
|
||||
# Shell will not recognize nupkg as a zip and throw, so rename it to zip
|
||||
$runtimeZip = [System.IO.Path]::ChangeExtension($DownloadFile, "zip")
|
||||
Rename-Item $runtimeFile $runtimeZip
|
||||
Rename-Item $DownloadFile $runtimeZip
|
||||
# Use the shell to uncompress the nupkg
|
||||
$shell_app=new-object -com shell.application
|
||||
$zip_file = $shell_app.namespace($runtimeZip)
|
||||
|
|
@ -597,7 +634,7 @@ function Ngen-Library(
|
|||
$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() {
|
||||
|
|
@ -859,7 +896,7 @@ function dnvm-upgrade {
|
|||
[Parameter(Mandatory=$false)]
|
||||
[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
|
||||
.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.
|
||||
.PARAMETER Persistent
|
||||
Make the installed runtime useable across all processes run by the current user
|
||||
.DESCRIPTION
|
||||
A proxy can also be specified by using the 'http_proxy' environment variable
|
||||
|
||||
|
|
@ -917,7 +956,10 @@ function dnvm-install {
|
|||
[switch]$NoNative,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[switch]$Ngen)
|
||||
[switch]$Ngen,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[switch]$Persistent)
|
||||
|
||||
if(!$VersionNuPkgOrAlias) {
|
||||
_WriteOut "A version, nupkg path, or the string 'latest' must be provided."
|
||||
|
|
@ -927,6 +969,7 @@ function dnvm-install {
|
|||
}
|
||||
|
||||
if ($VersionNuPkgOrAlias -eq "latest") {
|
||||
Write-Progress -Activity "Installing runtime" "Determining latest runtime" -Id 1
|
||||
$VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture
|
||||
}
|
||||
|
||||
|
|
@ -936,6 +979,7 @@ function dnvm-install {
|
|||
if(!(Test-Path $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)
|
||||
$Architecture = Get-PackageArch $runtimeFullName
|
||||
$Runtime = Get-PackageRuntime $runtimeFullName
|
||||
|
|
@ -974,14 +1018,17 @@ function dnvm-install {
|
|||
New-Item -Type Directory $UnpackFolder | Out-Null
|
||||
|
||||
if($IsNuPkg) {
|
||||
Write-Progress -Activity "Installing runtime" "Copying package" -Id 1
|
||||
_WriteDebug "Copying local nupkg $VersionNuPkgOrAlias to $DownloadFile"
|
||||
Copy-Item $VersionNuPkgOrAlias $DownloadFile
|
||||
} else {
|
||||
# Download the package
|
||||
Write-Progress -Activity "Installing runtime" "Downloading runtime" -Id 1
|
||||
_WriteDebug "Downloading version $VersionNuPkgOrAlias to $DownloadFile"
|
||||
Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy
|
||||
}
|
||||
|
||||
Write-Progress -Activity "Installing runtime" "Unpacking runtime" -Id 1
|
||||
Unpack-Package $DownloadFile $UnpackFolder
|
||||
|
||||
New-Item -Type Directory $RuntimeFolder -Force | Out-Null
|
||||
|
|
@ -991,12 +1038,13 @@ function dnvm-install {
|
|||
_WriteDebug "Cleaning temporary directory $UnpackFolder"
|
||||
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 (-not $NoNative) {
|
||||
if ((Is-Elevated) -or $Ngen) {
|
||||
$runtimeBin = Get-RuntimePath $runtimeFullName
|
||||
Write-Progress -Activity "Installing runtime" "Generating runtime native images" -Id 1
|
||||
Ngen-Library $runtimeBin $Architecture
|
||||
}
|
||||
else {
|
||||
|
|
@ -1006,12 +1054,18 @@ function dnvm-install {
|
|||
}
|
||||
elseif ($Runtime -eq "coreclr") {
|
||||
if ($NoNative) {
|
||||
_WriteOut "Skipping native image compilation."
|
||||
_WriteOut "Skipping native image compilation."
|
||||
}
|
||||
else {
|
||||
_WriteOut "Compiling native images for $runtimeFullName to improve startup performance..."
|
||||
Start-Process $CrossGenCommand -Wait
|
||||
_WriteOut "Finished native image compilation."
|
||||
_WriteOut "Compiling native images for $runtimeFullName to improve startup performance..."
|
||||
Write-Progress -Activity "Installing runtime" "Generating runtime native images" -Id 1
|
||||
if ($DebugPreference -eq 'SilentlyContinue') {
|
||||
Start-Process $CrossGenCommand -Wait -WindowStyle Hidden
|
||||
}
|
||||
else {
|
||||
Start-Process $CrossGenCommand -Wait -NoNewWindow
|
||||
}
|
||||
_WriteOut "Finished native image compilation."
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -1023,6 +1077,8 @@ function dnvm-install {
|
|||
_WriteDebug "Aliasing installed runtime to '$Alias'"
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
# 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
|
||||
Installs the version manager into your User profile directory
|
||||
|
|
@ -1140,28 +1230,12 @@ function dnvm-setup {
|
|||
|
||||
$ScriptFolder = Split-Path -Parent $ScriptPath
|
||||
|
||||
if(!(Test-Path $Destination)) {
|
||||
New-Item -Type Directory $Destination | Out-Null
|
||||
}
|
||||
|
||||
$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!"
|
||||
}
|
||||
# Copy script files (if necessary):
|
||||
Safe-Filecopy "$CommandName.ps1" $ScriptFolder $Destination
|
||||
Safe-Filecopy "$CommandName.cmd" $ScriptFolder $Destination
|
||||
|
||||
# Configure Environment Variables
|
||||
# Also, clean old user home values if present
|
||||
|
||||
# We'll be removing any existing homes, both
|
||||
$PathsToRemove = @(
|
||||
"%USERPROFILE%\$DefaultUserDirectoryName",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# Source this file from your .bash-profile or script to use
|
||||
|
||||
# "Constants"
|
||||
_DNVM_BUILDNUMBER="beta4-10345"
|
||||
_DNVM_BUILDNUMBER="beta4-10351"
|
||||
_DNVM_AUTHORS="Microsoft Open Technologies, Inc."
|
||||
_DNVM_RUNTIME_PACKAGE_NAME="dnx"
|
||||
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"
|
||||
|
|
@ -10,7 +10,7 @@ _DNVM_RUNTIME_SHORT_NAME="DNX"
|
|||
_DNVM_RUNTIME_FOLDER_NAME=".dnx"
|
||||
_DNVM_COMMAND_NAME="dnvm"
|
||||
_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_BUILDNUMBER" = "{{*" ] && _DNVM_BUILDNUMBER="HEAD"
|
||||
|
|
|
|||
Loading…
Reference in New Issue