@@ -28,6 +28,16 @@ function _WriteOut {
28
28
[Parameter (Mandatory = $false )][ConsoleColor ]$BackgroundColor ,
29
29
[Parameter (Mandatory = $false )][switch ]$NoNewLine )
30
30
31
+ if ($__TestWriteTo ) {
32
+ $cur = Get-Variable - Name $__TestWriteTo - ValueOnly - Scope Global - ErrorAction SilentlyContinue
33
+ $val = $cur + " $msg "
34
+ if (! $NoNewLine ) {
35
+ $val += [Environment ]::NewLine
36
+ }
37
+ Set-Variable - Name $__TestWriteTo - Value $val - Scope Global - Force
38
+ return
39
+ }
40
+
31
41
if (! $Script :UseWriteHost ) {
32
42
if (! $msg ) {
33
43
$msg = " "
@@ -53,20 +63,11 @@ function _WriteOut {
53
63
_WriteOut $msg
54
64
}
55
65
}
56
-
57
- if ($__TeeTo ) {
58
- $cur = Get-Variable - Name $__TeeTo - ValueOnly - Scope Global - ErrorAction SilentlyContinue
59
- $val = $cur + " $msg "
60
- if (! $NoNewLine ) {
61
- $val += [Environment ]::NewLine
62
- }
63
- Set-Variable - Name $__TeeTo - Value $val - Scope Global - Force
64
- }
65
66
}
66
67
67
68
# ## Constants
68
69
$ProductVersion = " 1.0.0"
69
- $BuildVersion = " beta5-10358 "
70
+ $BuildVersion = " beta5-10359 "
70
71
$Authors = " Microsoft Open Technologies, Inc."
71
72
72
73
# If the Version hasn't been replaced...
@@ -131,6 +132,7 @@ if(!$ColorScheme) {
131
132
}
132
133
133
134
Set-Variable - Option Constant " OptionPadding" 20
135
+ Set-Variable - Option Constant " CommandPadding" 15
134
136
135
137
# Test Control Variables
136
138
if ($__TeeTo ) {
@@ -216,6 +218,39 @@ $RuntimesDir = Join-Path $UserHome "runtimes"
216
218
$Aliases = $null
217
219
218
220
# ## Helper Functions
221
+ # Checks if a specified file exists in the destination folder and if not, copies the file
222
+ # to the destination folder.
223
+ function Safe-Filecopy {
224
+ param (
225
+ [Parameter (Mandatory = $true , Position = 0 )] $Filename ,
226
+ [Parameter (Mandatory = $true , Position = 1 )] $SourceFolder ,
227
+ [Parameter (Mandatory = $true , Position = 2 )] $DestinationFolder )
228
+
229
+ # Make sure the destination folder is created if it doesn't already exist.
230
+ if (! (Test-Path $DestinationFolder )) {
231
+ _WriteOut " Creating destination folder '$DestinationFolder ' ... "
232
+
233
+ New-Item - Type Directory $Destination | Out-Null
234
+ }
235
+
236
+ $sourceFilePath = Join-Path $SourceFolder $Filename
237
+ $destFilePath = Join-Path $DestinationFolder $Filename
238
+
239
+ if (Test-Path $sourceFilePath ) {
240
+ _WriteOut " Installing '$Filename ' to '$DestinationFolder ' ... "
241
+
242
+ if (Test-Path $destFilePath ) {
243
+ _WriteOut " Skipping: file already exists" - ForegroundColor Yellow
244
+ }
245
+ else {
246
+ Copy-Item $sourceFilePath $destFilePath - Force
247
+ }
248
+ }
249
+ else {
250
+ _WriteOut " WARNING: Unable to install: Could not find '$Filename ' in '$SourceFolder '. "
251
+ }
252
+ }
253
+
219
254
function GetArch ($Architecture , $FallBackArch = $DefaultArchitecture ) {
220
255
if (! [String ]::IsNullOrWhiteSpace($Architecture )) {
221
256
$Architecture
@@ -695,7 +730,7 @@ function dnvm-help {
695
730
if ($PassThru ) {
696
731
$help
697
732
} else {
698
- _WriteOut - ForegroundColor $ColorScheme.Help_Header " $CommandName - $Command "
733
+ _WriteOut - ForegroundColor $ColorScheme.Help_Header " $CommandName $Command "
699
734
_WriteOut " $ ( $help.Synopsis.Trim ()) "
700
735
_WriteOut
701
736
_WriteOut - ForegroundColor $ColorScheme.Help_Header " usage:"
@@ -776,7 +811,7 @@ function dnvm-help {
776
811
$name = $_.Name.Substring ($CommandPrefix.Length )
777
812
if ($DeprecatedCommands -notcontains $name ) {
778
813
_WriteOut - NoNewLine " "
779
- _WriteOut - NoNewLine - ForegroundColor $ColorScheme.Help_Command $name.PadRight (10 )
814
+ _WriteOut - NoNewLine - ForegroundColor $ColorScheme.Help_Command $name.PadRight ($CommandPadding )
780
815
_WriteOut " $ ( $h.Synopsis.Trim ()) "
781
816
}
782
817
}
@@ -1124,7 +1159,7 @@ function dnvm-install {
1124
1159
#>
1125
1160
function dnvm-use {
1126
1161
param (
1127
- [Parameter (Mandatory = $false , Position = 0 )]
1162
+ [Parameter (Mandatory = $true , Position = 0 )]
1128
1163
[string ]$VersionOrAlias ,
1129
1164
1130
1165
[Alias (" arch" )]
@@ -1141,13 +1176,6 @@ function dnvm-use {
1141
1176
[Parameter (Mandatory = $false )]
1142
1177
[switch ]$Persistent )
1143
1178
1144
- if ([String ]::IsNullOrWhiteSpace($VersionOrAlias )) {
1145
- _WriteOut " Missing version or alias to add to path"
1146
- dnvm- help use
1147
- $Script :ExitCode = $ExitCodes.InvalidArguments
1148
- return
1149
- }
1150
-
1151
1179
if ($versionOrAlias -eq " none" ) {
1152
1180
_WriteOut " Removing all runtimes from process PATH"
1153
1181
Set-Path (Change- Path $env: Path " " ($RuntimeDirs ))
@@ -1180,63 +1208,61 @@ function dnvm-use {
1180
1208
1181
1209
<#
1182
1210
. SYNOPSIS
1183
- Gets the full name of a runtime
1211
+ Locates the dnx.exe for the specified version or alias and executes it, providing the remaining arguments to dnx.exe
1184
1212
. PARAMETER VersionOrAlias
1185
- The version or alias of the runtime to place on the PATH
1186
- . PARAMETER Architecture
1187
- The processor architecture of the runtime to place on the PATH (default: x86, or whatever the alias specifies in the case of use-ing an alias)
1188
- . PARAMETER Runtime
1189
- The runtime flavor of the runtime to place on the PATH (default: clr, or whatever the alias specifies in the case of use-ing an alias)
1213
+ The version of alias of the runtime to execute
1214
+ . PARAMETER DnxArguments
1215
+ The arguments to pass to dnx.exe
1190
1216
#>
1191
- function dnvm-name {
1217
+ function dnvm-run {
1192
1218
param (
1193
- [Parameter (Mandatory = $false , Position = 0 )]
1219
+ [Parameter (Mandatory = $true , Position = 0 )]
1194
1220
[string ]$VersionOrAlias ,
1221
+ [Parameter (Mandatory = $false , Position = 1 , ValueFromRemainingArguments = $true )]
1222
+ [object []]$DnxArguments )
1195
1223
1196
- [ Alias ( " arch " )]
1197
- [ ValidateSet ( " x86 " , " x64 " )]
1198
- [ Parameter ( Mandatory = $false )]
1199
- [ string ] $Architecture = " " ,
1200
-
1201
- [ Alias ( " r " )]
1202
- [ ValidateSet ( " clr " , " coreclr " )]
1203
- [ Parameter ( Mandatory = $false )]
1204
- [ string ] $Runtime = " " )
1205
-
1206
- Get-RuntimeName $VersionOrAlias $Architecture $Runtime
1224
+ $runtimeFullName = Get-RuntimeName $VersionOrAlias $Architecture $Runtime
1225
+ $runtimeBin = Get-RuntimePath $runtimeFullName
1226
+ if ( $runtimeBin -eq $null ) {
1227
+ throw " Cannot find $runtimeFullName , do you need to run ' $CommandName install $versionOrAlias '? "
1228
+ }
1229
+ $dnxExe = Join-Path $runtimeBin " dnx.exe "
1230
+ if ( ! ( Test-Path $dnxExe )) {
1231
+ throw " Cannot find a dnx.exe in $runtimeBin , the installation may be corrupt. Try running 'dnvm install $VersionOrAlias -f' to reinstall it "
1232
+ }
1233
+ _WriteDebug " > $dnxExe $DnxArguments "
1234
+ & $dnxExe @DnxArguments
1207
1235
}
1208
1236
1209
-
1210
- # Checks if a specified file exists in the destination folder and if not, copies the file
1211
- # to the destination folder.
1212
- function Safe-Filecopy {
1237
+ <#
1238
+ . SYNOPSIS
1239
+ Executes the specified command in a sub-shell where the PATH has been augmented to include the specified DNX
1240
+ . PARAMETER VersionOrAlias
1241
+ The version of alias of the runtime to make active in the sub-shell
1242
+ . PARAMETER Command
1243
+ The command to execute in the sub-shell
1244
+ #>
1245
+ function dnvm-exec {
1213
1246
param (
1214
- [Parameter (Mandatory = $true , Position = 0 )] $Filename ,
1215
- [Parameter (Mandatory = $true , Position = 1 )] $SourceFolder ,
1216
- [Parameter (Mandatory = $true , Position = 2 )] $DestinationFolder )
1247
+ [Parameter (Mandatory = $true , Position = 0 )]
1248
+ [string ]$VersionOrAlias ,
1249
+ [Parameter (Mandatory = $false , Position = 1 )]
1250
+ [string ]$Command ,
1251
+ [Parameter (Mandatory = $false , Position = 2 , ValueFromRemainingArguments = $true )]
1252
+ [object []]$Arguments )
1217
1253
1218
- # Make sure the destination folder is created if it doesn't already exist.
1219
- if (! (Test-Path $DestinationFolder )) {
1220
- _WriteOut " Creating destination folder '$DestinationFolder ' ... "
1221
-
1222
- New-Item - Type Directory $Destination | Out-Null
1254
+ $runtimeFullName = Get-RuntimeName $VersionOrAlias $Architecture $Runtime
1255
+ $runtimeBin = Get-RuntimePath $runtimeFullName
1256
+ if ($runtimeBin -eq $null ) {
1257
+ throw " Cannot find $runtimeFullName , do you need to run '$CommandName install $versionOrAlias '?"
1223
1258
}
1224
1259
1225
- $sourceFilePath = Join-Path $SourceFolder $Filename
1226
- $destFilePath = Join-Path $DestinationFolder $Filename
1227
-
1228
- if (Test-Path $sourceFilePath ) {
1229
- _WriteOut " Installing '$Filename ' to '$DestinationFolder ' ... "
1230
-
1231
- if (Test-Path $destFilePath ) {
1232
- _WriteOut " Skipping: file already exists" - ForegroundColor Yellow
1233
- }
1234
- else {
1235
- Copy-Item $sourceFilePath $destFilePath - Force
1236
- }
1237
- }
1238
- else {
1239
- _WriteOut " WARNING: Unable to install: Could not find '$Filename ' in '$SourceFolder '. "
1260
+ $oldPath = $env: PATH
1261
+ try {
1262
+ $env: PATH = " $runtimeBin ;$ ( $env: PATH ) "
1263
+ & $Command @Arguments
1264
+ } finally {
1265
+ $env: PATH = $oldPath
1240
1266
}
1241
1267
}
1242
1268
0 commit comments