Skip to content

Commit 0d52700

Browse files
ASP.NET Push Botunknown
authored andcommitted
⬆️ dnvm.ps1, dnvm.cmd, dnvm.sh
Source: aspnet/dnvm@fc63c6c
1 parent 4f92744 commit 0d52700

File tree

2 files changed

+213
-52
lines changed

2 files changed

+213
-52
lines changed

dnvm.ps1

Lines changed: 70 additions & 15 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="beta8-15502"
70+
$BuildVersion="beta8-15506"
7171
$Authors="Microsoft Open Technologies, Inc."
7272

7373
# If the Version hasn't been replaced...
@@ -82,6 +82,7 @@ $FullVersion="$ProductVersion-$BuildVersion"
8282
Set-Variable -Option Constant "CommandName" ([IO.Path]::GetFileNameWithoutExtension($ScriptPath))
8383
Set-Variable -Option Constant "CommandFriendlyName" ".NET Version Manager"
8484
Set-Variable -Option Constant "DefaultUserDirectoryName" ".dnx"
85+
Set-Variable -Option Constant "DefaultGlobalDirectoryName" "Microsoft DNX"
8586
Set-Variable -Option Constant "OldUserDirectoryNames" @(".kre", ".k")
8687
Set-Variable -Option Constant "RuntimePackageName" "dnx"
8788
Set-Variable -Option Constant "DefaultFeed" "https://www.nuget.org/api/v2"
@@ -155,6 +156,7 @@ $DeprecatedCommands = @("unalias")
155156
# Load Environment variables
156157
$RuntimeHomes = $env:DNX_HOME
157158
$UserHome = $env:DNX_USER_HOME
159+
$GlobalHome = $env:DNX_GLOBAL_HOME
158160
$ActiveFeed = $env:DNX_FEED
159161
$ActiveUnstableFeed = $env:DNX_UNSTABLE_FEED
160162

@@ -182,11 +184,24 @@ if($CmdPathFile) {
182184
# Determine where runtimes can exist (RuntimeHomes)
183185
if(!$RuntimeHomes) {
184186
# Set up a default value for the runtime home
185-
$UnencodedHomes = "%USERPROFILE%\$DefaultUserDirectoryName"
187+
$UnencodedHomes = "$env:USERPROFILE\$DefaultUserDirectoryName;$GlobalHome\$DefaultGlobalDirectoryName"
186188
} else {
187189
$UnencodedHomes = $RuntimeHomes
188190
}
189191

192+
# Determine the default global installation directory (GlobalHome)
193+
if(!$GlobalHome) {
194+
if($env:ProgramData) {
195+
$GlobalHome = "$env:ProgramData\$DefaultGlobalDirectoryName"
196+
} else {
197+
$GlobalHome = "$env:AllUsersProfile\$DefaultGlobalDirectoryName"
198+
}
199+
200+
$env:DNX_GLOBAL_HOME="$GlobalHome"
201+
$env:DNX_HOME="$env:DNX_HOME;$env:DNX_GLOBAL_HOME"
202+
$UnencodedHomes = "$UnencodedHomes;$GlobalHome"
203+
}
204+
190205
$UnencodedHomes = $UnencodedHomes.Split(";")
191206
$RuntimeHomes = $UnencodedHomes | ForEach-Object { [Environment]::ExpandEnvironmentVariables($_) }
192207
$RuntimeDirs = $RuntimeHomes | ForEach-Object { Join-Path $_ "runtimes" }
@@ -221,6 +236,7 @@ _WriteDebug "Runtime Homes: $RuntimeHomes"
221236
_WriteDebug "User Home: $UserHome"
222237
$AliasesDir = Join-Path $UserHome "alias"
223238
$RuntimesDir = Join-Path $UserHome "runtimes"
239+
$GlobalRuntimesDir = Join-Path $GlobalHome "runtimes"
224240
$Aliases = $null
225241

226242
### Helper Functions
@@ -394,7 +410,7 @@ function Get-RuntimeAliasOrRuntimeInfo(
394410
}
395411

396412
filter List-Parts {
397-
param($aliases)
413+
param($aliases, $items)
398414

399415
$location = ""
400416

@@ -422,6 +438,20 @@ filter List-Parts {
422438
$parts2 += "x86/x64"
423439
}
424440

441+
$aliasUsed = ""
442+
if($items) {
443+
$aliasUsed = $items | ForEach-Object {
444+
if($_.Architecture -eq $parts2[3] -and $_.Runtime -eq $parts2[1] -and $_.OperatingSystem -eq $parts2[2] -and $_.Version -eq $parts1[1]) {
445+
return $true;
446+
}
447+
return $false;
448+
}
449+
}
450+
451+
if($aliasUsed -eq $true) {
452+
$fullAlias = ""
453+
}
454+
425455
return New-Object PSObject -Property @{
426456
Active = $active
427457
Version = $parts1[1]
@@ -693,7 +723,7 @@ function Get-RuntimePath($runtimeFullName) {
693723
foreach($RuntimeHome in $RuntimeHomes) {
694724
$runtimeBin = "$RuntimeHome\runtimes\$runtimeFullName\bin"
695725
_WriteDebug " Candidate $runtimeBin"
696-
if (Test-Path "$runtimeBin") {
726+
if (Test-Path $runtimeBin) {
697727
_WriteDebug " Found in $runtimeBin"
698728
return $runtimeBin
699729
}
@@ -976,7 +1006,7 @@ function dnvm-list {
9761006
$RuntimeHomes | ForEach-Object {
9771007
_WriteDebug "Scanning $_ for runtimes..."
9781008
if (Test-Path "$_\runtimes") {
979-
$items += Get-ChildItem "$_\runtimes\$RuntimePackageName-*" | List-Parts $aliases
1009+
$items += Get-ChildItem "$_\runtimes\$RuntimePackageName-*" | List-Parts $aliases $items
9801010
}
9811011
}
9821012

@@ -1104,7 +1134,9 @@ function dnvm-unalias {
11041134
.PARAMETER Ngen
11051135
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.
11061136
.PARAMETER Unstable
1107-
Upgrade from our unstable dev feed. This will give you the latest development version of the runtime.
1137+
Upgrade from the unstable dev feed. This will give you the latest development version of the runtime.
1138+
.PARAMETER Global
1139+
Installs to configured global dnx file location (default: C:\ProgramData)
11081140
#>
11091141
function dnvm-upgrade {
11101142
param(
@@ -1140,7 +1172,10 @@ function dnvm-upgrade {
11401172
[switch]$Ngen,
11411173

11421174
[Parameter(Mandatory=$false)]
1143-
[switch]$Unstable)
1175+
[switch]$Unstable,
1176+
1177+
[Parameter(Mandatory=$false)]
1178+
[switch]$Global)
11441179

11451180
if($OS -ne "win" -and ![String]::IsNullOrEmpty($OS)) {
11461181
#We could remove OS as an option from upgrade, but I want to take this opporunty to educate users about the difference between install and upgrade
@@ -1150,7 +1185,7 @@ function dnvm-upgrade {
11501185
return
11511186
}
11521187

1153-
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -OS:$OS -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Unstable:$Unstable -Persistent:$true
1188+
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -OS:$OS -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Unstable:$Unstable -Persistent:$true -Global:$Global
11541189
}
11551190

11561191
<#
@@ -1179,7 +1214,9 @@ function dnvm-upgrade {
11791214
.PARAMETER Persistent
11801215
Make the installed runtime useable across all processes run by the current user
11811216
.PARAMETER Unstable
1182-
Upgrade from our unstable dev feed. This will give you the latest development version of the runtime.
1217+
Upgrade from the unstable dev feed. This will give you the latest development version of the runtime.
1218+
.PARAMETER Global
1219+
Installs to configured global dnx file location (default: C:\ProgramData)
11831220
.DESCRIPTION
11841221
A proxy can also be specified by using the 'http_proxy' environment variable
11851222
#>
@@ -1223,7 +1260,10 @@ function dnvm-install {
12231260
[switch]$Persistent,
12241261

12251262
[Parameter(Mandatory=$false)]
1226-
[switch]$Unstable)
1263+
[switch]$Unstable,
1264+
1265+
[Parameter(Mandatory=$false)]
1266+
[switch]$Global)
12271267

12281268
$selectedFeed = ""
12291269

@@ -1279,7 +1319,7 @@ function dnvm-install {
12791319
$Version = Get-PackageVersion $BaseName
12801320
}
12811321

1282-
if([String]::IsNullOrEmpty($Architecture)) {
1322+
if([String]::IsNullOrEmpty($OS)) {
12831323
$OS = Get-PackageOS $BaseName
12841324
}
12851325
} else {
@@ -1313,16 +1353,31 @@ function dnvm-install {
13131353
_WriteDebug "Version: $($runtimeInfo.Version)"
13141354
_WriteDebug "OS: $($runtimeInfo.OS)"
13151355

1316-
$RuntimeFolder = Join-Path $RuntimesDir $($runtimeInfo.RuntimeName)
1356+
$installDir = $RuntimesDir
1357+
if (!$Global) {
1358+
$RuntimeFolder = Join-Path $RuntimesDir $($runtimeInfo.RuntimeName)
1359+
}
1360+
else {
1361+
$installDir = $GlobalRuntimesDir
1362+
$RuntimeFolder = Join-Path $GlobalRuntimesDir $($runtimeInfo.RuntimeName)
1363+
}
1364+
13171365
_WriteDebug "Destination: $RuntimeFolder"
13181366

13191367
if((Test-Path $RuntimeFolder) -and $Force) {
13201368
_WriteOut "Cleaning existing installation..."
13211369
Remove-Item $RuntimeFolder -Recurse -Force
13221370
}
13231371

1324-
if(Test-Path $RuntimeFolder) {
1325-
_WriteOut "'$($runtimeInfo.RuntimeName)' is already installed."
1372+
$installed=""
1373+
if(Test-Path (Join-Path $RuntimesDir $($runtimeInfo.RuntimeName))) {
1374+
$installed = Join-Path $RuntimesDir $($runtimeInfo.RuntimeName)
1375+
}
1376+
if(Test-Path (Join-Path $GlobalRuntimesDir $($runtimeInfo.RuntimeName))) {
1377+
$installed = Join-Path $GlobalRuntimesDir $($runtimeInfo.RuntimeName)
1378+
}
1379+
if($installed -ne "") {
1380+
_WriteOut "'$($runtimeInfo.RuntimeName)' is already installed in $installed."
13261381
if($runtimeInfo.OS -eq "win") {
13271382
dnvm-use $runtimeInfo.Version -Architecture:$runtimeInfo.Architecture -Runtime:$runtimeInfo.Runtime -Persistent:$Persistent -OS:$runtimeInfo.OS
13281383
}
@@ -1333,7 +1388,7 @@ function dnvm-install {
13331388
$Runtime = $runtimeInfo.Runtime
13341389
$OS = $runtimeInfo.OS
13351390

1336-
$TempFolder = Join-Path $RuntimesDir "temp"
1391+
$TempFolder = Join-Path $installDir "temp"
13371392
$UnpackFolder = Join-Path $TempFolder $runtimeFullName
13381393
$DownloadFile = Join-Path $UnpackFolder "$runtimeFullName.nupkg"
13391394

0 commit comments

Comments
 (0)