@@ -28,6 +28,16 @@ function _WriteOut {
2828 [Parameter (Mandatory = $false )][ConsoleColor ]$BackgroundColor ,
2929 [Parameter (Mandatory = $false )][switch ]$NoNewLine )
3030
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+
3141 if (! $Script :UseWriteHost ) {
3242 if (! $msg ) {
3343 $msg = " "
@@ -53,20 +63,11 @@ function _WriteOut {
5363 _WriteOut $msg
5464 }
5565 }
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- }
6566}
6667
6768# ## Constants
6869$ProductVersion = " 1.0.0"
69- $BuildVersion = " beta5-10358 "
70+ $BuildVersion = " beta5-10359 "
7071$Authors = " Microsoft Open Technologies, Inc."
7172
7273# If the Version hasn't been replaced...
@@ -131,6 +132,7 @@ if(!$ColorScheme) {
131132}
132133
133134Set-Variable - Option Constant " OptionPadding" 20
135+ Set-Variable - Option Constant " CommandPadding" 15
134136
135137# Test Control Variables
136138if ($__TeeTo ) {
@@ -216,6 +218,39 @@ $RuntimesDir = Join-Path $UserHome "runtimes"
216218$Aliases = $null
217219
218220# ## 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+
219254function GetArch ($Architecture , $FallBackArch = $DefaultArchitecture ) {
220255 if (! [String ]::IsNullOrWhiteSpace($Architecture )) {
221256 $Architecture
@@ -695,7 +730,7 @@ function dnvm-help {
695730 if ($PassThru ) {
696731 $help
697732 } else {
698- _WriteOut - ForegroundColor $ColorScheme.Help_Header " $CommandName - $Command "
733+ _WriteOut - ForegroundColor $ColorScheme.Help_Header " $CommandName $Command "
699734 _WriteOut " $ ( $help.Synopsis.Trim ()) "
700735 _WriteOut
701736 _WriteOut - ForegroundColor $ColorScheme.Help_Header " usage:"
@@ -776,7 +811,7 @@ function dnvm-help {
776811 $name = $_.Name.Substring ($CommandPrefix.Length )
777812 if ($DeprecatedCommands -notcontains $name ) {
778813 _WriteOut - NoNewLine " "
779- _WriteOut - NoNewLine - ForegroundColor $ColorScheme.Help_Command $name.PadRight (10 )
814+ _WriteOut - NoNewLine - ForegroundColor $ColorScheme.Help_Command $name.PadRight ($CommandPadding )
780815 _WriteOut " $ ( $h.Synopsis.Trim ()) "
781816 }
782817 }
@@ -1124,7 +1159,7 @@ function dnvm-install {
11241159#>
11251160function dnvm-use {
11261161 param (
1127- [Parameter (Mandatory = $false , Position = 0 )]
1162+ [Parameter (Mandatory = $true , Position = 0 )]
11281163 [string ]$VersionOrAlias ,
11291164
11301165 [Alias (" arch" )]
@@ -1141,13 +1176,6 @@ function dnvm-use {
11411176 [Parameter (Mandatory = $false )]
11421177 [switch ]$Persistent )
11431178
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-
11511179 if ($versionOrAlias -eq " none" ) {
11521180 _WriteOut " Removing all runtimes from process PATH"
11531181 Set-Path (Change- Path $env: Path " " ($RuntimeDirs ))
@@ -1180,63 +1208,61 @@ function dnvm-use {
11801208
11811209<#
11821210. 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
11841212. 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
11901216#>
1191- function dnvm-name {
1217+ function dnvm-run {
11921218 param (
1193- [Parameter (Mandatory = $false , Position = 0 )]
1219+ [Parameter (Mandatory = $true , Position = 0 )]
11941220 [string ]$VersionOrAlias ,
1221+ [Parameter (Mandatory = $false , Position = 1 , ValueFromRemainingArguments = $true )]
1222+ [object []]$DnxArguments )
11951223
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
12071235}
12081236
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 {
12131246 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 )
12171253
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 '?"
12231258 }
12241259
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
12401266 }
12411267}
12421268
0 commit comments