Skip to content

Commit e9dbf24

Browse files
ASP.NET Push Botunknown
authored andcommitted
⬆️ dnvm.ps1, dnvm.cmd, dnvm.sh
Source: aspnet/dnvm@9c54d02
1 parent 578f542 commit e9dbf24

File tree

2 files changed

+140
-37
lines changed

2 files changed

+140
-37
lines changed

dnvm.ps1

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function _WriteOut {
6767

6868
### Constants
6969
$ProductVersion="1.0.0"
70-
$BuildVersion="beta5-10365"
70+
$BuildVersion="beta5-10367"
7171
$Authors="Microsoft Open Technologies, Inc."
7272

7373
# If the Version hasn't been replaced...
@@ -84,7 +84,8 @@ Set-Variable -Option Constant "CommandFriendlyName" ".NET Version Manager"
8484
Set-Variable -Option Constant "DefaultUserDirectoryName" ".dnx"
8585
Set-Variable -Option Constant "OldUserDirectoryNames" @(".kre", ".k")
8686
Set-Variable -Option Constant "RuntimePackageName" "dnx"
87-
Set-Variable -Option Constant "DefaultFeed" "https://www.myget.org/F/aspnetvnext/api/v2"
87+
Set-Variable -Option Constant "DefaultFeed" "https://www.nuget.org/api/v2"
88+
Set-Variable -Option Constant "DefaultUnstableFeed" "https://www.myget.org/F/aspnetvnext/api/v2"
8889
Set-Variable -Option Constant "CrossGenCommand" "k-crossgen"
8990
Set-Variable -Option Constant "CommandPrefix" "dnvm-"
9091
Set-Variable -Option Constant "DefaultArchitecture" "x86"
@@ -128,6 +129,8 @@ if(!$ColorScheme) {
128129
"Help_Optional"=[ConsoleColor]::Gray
129130
"Help_Command"=[ConsoleColor]::DarkYellow
130131
"Help_Executable"=[ConsoleColor]::DarkYellow
132+
"Feed_Name"=[ConsoleColor]::Cyan
133+
"Warning" = [ConsoleColor]::Yellow
131134
}
132135
}
133136

@@ -147,6 +150,7 @@ $DeprecatedCommands = @("unalias")
147150
$RuntimeHomes = $env:DNX_HOME
148151
$UserHome = $env:DNX_USER_HOME
149152
$ActiveFeed = $env:DNX_FEED
153+
$ActiveUnstableFeed = $env:DNX_UNSTABLE_FEED
150154

151155
# Default Exit Code
152156
$Script:ExitCode = $ExitCodes.Success
@@ -169,10 +173,6 @@ if($CmdPathFile) {
169173
_WriteDebug "Using CMD PATH file: $CmdPathFile"
170174
}
171175

172-
if(!$ActiveFeed) {
173-
$ActiveFeed = $DefaultFeed
174-
}
175-
176176
# Determine where runtimes can exist (RuntimeHomes)
177177
if(!$RuntimeHomes) {
178178
# Set up a default value for the runtime home
@@ -275,13 +275,34 @@ function Write-Usage {
275275
if(!$Authors.StartsWith("{{")) {
276276
_WriteOut "By $Authors"
277277
}
278-
_WriteOut
279278
_WriteOut -NoNewLine -ForegroundColor $ColorScheme.Help_Header "usage:"
280279
_WriteOut -NoNewLine -ForegroundColor $ColorScheme.Help_Executable " $CommandName"
281280
_WriteOut -NoNewLine -ForegroundColor $ColorScheme.Help_Command " <command>"
282281
_WriteOut -ForegroundColor $ColorScheme.Help_Argument " [<arguments...>]"
283282
}
284283

284+
function Write-Feeds {
285+
_WriteOut
286+
_WriteOut -ForegroundColor $ColorScheme.Help_Header "Current feed settings:"
287+
_WriteOut -NoNewline -ForegroundColor $ColorScheme.Feed_Name "Default Stable: "
288+
_WriteOut "$DefaultFeed"
289+
_WriteOut -NoNewline -ForegroundColor $ColorScheme.Feed_Name "Default Unstable: "
290+
_WriteOut "$DefaultUnstableFeed"
291+
_WriteOut -NoNewline -ForegroundColor $ColorScheme.Feed_Name "Current Stable Override: "
292+
if($ActiveFeed) {
293+
_WriteOut "$ActiveFeed"
294+
} else {
295+
_WriteOut "<none>"
296+
}
297+
_WriteOut -NoNewline -ForegroundColor $ColorScheme.Feed_Name "Current Unstable Override: "
298+
if($ActiveUnstableFeed) {
299+
_WriteOut "$ActiveUnstableFeed"
300+
} else {
301+
_WriteOut "<none>"
302+
}
303+
304+
}
305+
285306
function Get-RuntimeAlias {
286307
if($Aliases -eq $null) {
287308
_WriteDebug "Scanning for aliases in $AliasesDir"
@@ -440,16 +461,15 @@ function Find-Latest {
440461
param(
441462
[string]$runtime = "",
442463
[string]$architecture = "",
464+
[Parameter(Mandatory=$true)]
443465
[string]$Feed,
444466
[string]$Proxy
445467
)
446-
if(!$Feed) { $Feed = $ActiveFeed }
447468

448469
_WriteOut "Determining latest version"
449470

450471
$RuntimeId = Get-RuntimeId -Architecture:"$architecture" -Runtime:"$runtime"
451472
$url = "$Feed/GetUpdates()?packageIds=%27$RuntimeId%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
452-
453473
# NOTE: DO NOT use Invoke-WebRequest. It requires PowerShell 4.0!
454474

455475
$wc = New-Object System.Net.WebClient
@@ -464,9 +484,11 @@ function Find-Latest {
464484

465485
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
466486

467-
if (![String]::IsNullOrWhiteSpace($version)) {
487+
if($version) {
468488
_WriteDebug "Found latest version: $version"
469489
$version
490+
} else {
491+
throw "There are no runtimes matching the name $RuntimeId on feed $feed."
470492
}
471493
}
472494

@@ -496,11 +518,10 @@ function Download-Package(
496518
[string]$Architecture,
497519
[string]$Runtime,
498520
[string]$DestinationFile,
521+
[Parameter(Mandatory=$true)]
499522
[string]$Feed,
500523
[string]$Proxy) {
501524

502-
if(!$Feed) { $Feed = $ActiveFeed }
503-
504525
$url = "$Feed/package/" + (Get-RuntimeId $Architecture $Runtime) + "/" + $Version
505526

506527
_WriteOut "Downloading $runtimeFullName from $feed"
@@ -531,8 +552,12 @@ function Download-Package(
531552
}
532553
}
533554

534-
if($Global:downloadData.Error){
535-
throw "Unable to download package: {0}" -f $Global:downloadData.Error.Message
555+
if($Global:downloadData.Error) {
556+
if($Global:downloadData.Error.Response.StatusCode -eq [System.Net.HttpStatusCode]::NotFound){
557+
throw "The server returned a 404 (NotFound). This is most likely caused by the feed not having the version that you typed. Check that you typed the right version and try again. Other possible causes are the feed doesn't have a $RuntimeShortFriendlyName of the right name format or some other error caused a 404 on the server."
558+
} else {
559+
throw "Unable to download package: {0}" -f $Global:downloadData.Error.Message
560+
}
536561
}
537562

538563
Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $url") -Id 2 -ParentId 1 -Completed
@@ -803,6 +828,7 @@ function dnvm-help {
803828
}
804829
} else {
805830
Write-Usage
831+
Write-Feeds
806832
_WriteOut
807833
_WriteOut -ForegroundColor $ColorScheme.Help_Header "commands: "
808834
Get-Command "$CommandPrefix*" |
@@ -928,6 +954,8 @@ function dnvm-unalias {
928954
Skip generation of native images
929955
.PARAMETER Ngen
930956
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.
957+
.PARAMETER Unstable
958+
Upgrade from our unstable dev feed. This will give you the latest development version of the runtime.
931959
#>
932960
function dnvm-upgrade {
933961
param(
@@ -956,9 +984,12 @@ function dnvm-upgrade {
956984
[switch]$NoNative,
957985

958986
[Parameter(Mandatory=$false)]
959-
[switch]$Ngen)
987+
[switch]$Ngen,
988+
989+
[Parameter(Mandatory=$false)]
990+
[switch]$Unstable)
960991

961-
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Persistent:$true
992+
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Unstable:$Unstable -Persistent:$true
962993
}
963994

964995
<#
@@ -984,9 +1015,10 @@ function dnvm-upgrade {
9841015
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.
9851016
.PARAMETER Persistent
9861017
Make the installed runtime useable across all processes run by the current user
1018+
.PARAMETER Unstable
1019+
Upgrade from our unstable dev feed. This will give you the latest development version of the runtime.
9871020
.DESCRIPTION
9881021
A proxy can also be specified by using the 'http_proxy' environment variable
989-
9901022
#>
9911023
function dnvm-install {
9921024
param(
@@ -1021,7 +1053,28 @@ function dnvm-install {
10211053
[switch]$Ngen,
10221054

10231055
[Parameter(Mandatory=$false)]
1024-
[switch]$Persistent)
1056+
[switch]$Persistent,
1057+
1058+
[Parameter(Mandatory=$false)]
1059+
[switch]$Unstable)
1060+
1061+
$selectedFeed = ""
1062+
1063+
if($Unstable) {
1064+
$selectedFeed = $ActiveUnstableFeed
1065+
if(!$selectedFeed) {
1066+
$selectedFeed = $DefaultUnstableFeed
1067+
} else {
1068+
_WriteOut -ForegroundColor $ColorScheme.Warning "Default unstable feed ($DefaultUnstableFeed) is being overridden by the value of the DNX_UNSTABLE_FEED environment variable ($ActiveUnstableFeed)"
1069+
}
1070+
} else {
1071+
$selectedFeed = $ActiveFeed
1072+
if(!$selectedFeed) {
1073+
$selectedFeed = $DefaultFeed
1074+
} else {
1075+
_WriteOut -ForegroundColor $ColorScheme.Warning "Default stable feed ($DefaultFeed) is being overridden by the value of the DNX_FEED environment variable ($ActiveFeed)"
1076+
}
1077+
}
10251078

10261079
if(!$VersionNuPkgOrAlias) {
10271080
_WriteOut "A version, nupkg path, or the string 'latest' must be provided."
@@ -1032,7 +1085,7 @@ function dnvm-install {
10321085

10331086
if ($VersionNuPkgOrAlias -eq "latest") {
10341087
Write-Progress -Activity "Installing runtime" "Determining latest runtime" -Id 1
1035-
$VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture
1088+
$VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture -Feed:$selectedFeed
10361089
}
10371090

10381091
$IsNuPkg = $VersionNuPkgOrAlias.EndsWith(".nupkg")
@@ -1088,7 +1141,8 @@ function dnvm-install {
10881141
# Download the package
10891142
Write-Progress -Activity "Installing runtime" "Downloading runtime" -Id 1
10901143
_WriteDebug "Downloading version $VersionNuPkgOrAlias to $DownloadFile"
1091-
Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy
1144+
1145+
Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy -Feed:$selectedFeed
10921146
}
10931147

10941148
Write-Progress -Activity "Installing runtime" "Unpacking runtime" -Id 1
@@ -1382,7 +1436,7 @@ try {
13821436
$Script:ExitCode = $ExitCodes.UnknownCommand
13831437
}
13841438
} catch {
1385-
Write-Error $_
1439+
throw
13861440
if(!$Script:ExitCode) { $Script:ExitCode = $ExitCodes.OtherError }
13871441
}
13881442

0 commit comments

Comments
 (0)