@@ -87,9 +87,7 @@ function Invoke-Task
8787 Assert ((test-path " variable:$variable " ) -and ((get-variable $variable ).Value -ne $null )) ($msgs.required_variable_not_set -f $variable , $taskName )
8888 }
8989
90- Exec $task.Action `
91- - maxRetries $task.MaxRetries `
92- - retryTriggerErrorPattern $task.RetryTriggerErrorPattern
90+ & $task.Action
9391
9492 if ($task.PostAction ) {
9593 & $task.PostAction
@@ -143,7 +141,7 @@ function Exec
143141
144142 do {
145143 try {
146- $global :lastexitcode = 0
144+ $global :lastexitcode = 0
147145 & $cmd
148146 if ($lastexitcode -ne 0 ) {
149147 throw (" Exec: " + $errorMessage )
@@ -298,6 +296,7 @@ function Framework {
298296 [Parameter (Position = 0 , Mandatory = 1 )][string ]$framework
299297 )
300298 $psake.context.Peek ().config.framework = $framework
299+ ConfigureBuildEnvironment
301300}
302301
303302# . ExternalHelp psake.psm1-help.xml
@@ -311,16 +310,20 @@ function Invoke-psake {
311310 [Parameter (Position = 4 , Mandatory = 0 )][hashtable ] $parameters = @ {},
312311 [Parameter (Position = 5 , Mandatory = 0 )][hashtable ] $properties = @ {},
313312 [Parameter (Position = 6 , Mandatory = 0 )][alias (" init" )][scriptblock ] $initialization = {},
314- [Parameter (Position = 7 , Mandatory = 0 )][switch ] $nologo = $false
313+ [Parameter (Position = 7 , Mandatory = 0 )][switch ] $nologo = $false ,
314+ [Parameter (Position = 8 , Mandatory = 0 )][switch ] $detailedDocs = $false
315315 )
316316 try {
317317 if (-not $nologo ) {
318- " psake version {0}`n Copyright (c) 2010 James Kovacs`n " -f $psake.version
318+ " psake version {0}`n Copyright (c) 2010-2014 James Kovacs & Contributors `n " -f $psake.version
319319 }
320320
321- # If the default.ps1 file exists and the given "buildfile" isn 't found assume that the given
322- # $buildFile is actually the target Tasks to execute in the default.ps1 script.
323- if ($buildFile -and ! (test-path $buildFile - pathType Leaf) -and (test-path $psake.config_default.buildFileName - pathType Leaf)) {
321+ if (! $buildFile ) {
322+ $buildFile = $psake.config_default.buildFileName
323+ }
324+ elseif (! (test-path $buildFile - pathType Leaf) -and (test-path $psake.config_default.buildFileName - pathType Leaf)) {
325+ # If the $config.buildFileName file exists and the given "buildfile" isn 't found assume that the given
326+ # $buildFile is actually the target Tasks to execute in the $config.buildFileName script.
324327 $taskList = $buildFile.Split (' , ' )
325328 $buildFile = $psake.config_default.buildFileName
326329 }
@@ -349,12 +352,12 @@ function Invoke-psake {
349352
350353 LoadConfiguration $psake.build_script_dir
351354
352- LoadModules
353-
354355 $stopwatch = [System.Diagnostics.Stopwatch ]::StartNew()
355356
356357 set-location $psake.build_script_dir
357358
359+ LoadModules
360+
358361 $frameworkOldValue = $framework
359362 . $psake.build_script_file.FullName
360363
@@ -372,8 +375,8 @@ function Invoke-psake {
372375 . $includeFilename
373376 }
374377
375- if ($docs ) {
376- WriteDocumentation
378+ if ($docs -or $detailedDocs ) {
379+ WriteDocumentation( $detailedDocs )
377380 CleanupEnvironment
378381 return
379382 }
@@ -437,14 +440,14 @@ function Invoke-psake {
437440 $psake.build_success = $false
438441
439442 # if we are running in a nested scope (i.e. running a psake script from a psake script) then we need to re-throw the exception
440- # so that the parent script will fail otherwise the parent script will report a successful build
443+ # so that the parent script will fail otherwise the parent script will report a successful build
441444 $inNestedScope = ($psake.context.count -gt 1 )
442445 if ( $inNestedScope ) {
443446 throw $_
444447 } else {
445- if (! $psake.run_by_psake_build_tester ) {
446- WriteColoredOutput $error_message - foregroundcolor Red
447- }
448+ if (! $psake.run_by_psake_build_tester ) {
449+ WriteColoredOutput $error_message - foregroundcolor Red
450+ }
448451 }
449452 } finally {
450453 CleanupEnvironment
@@ -557,6 +560,7 @@ function ConfigureBuildEnvironment {
557560 throw ($msgs.error_invalid_framework -f $framework )
558561 }
559562 $versions = $null
563+ $buildToolsVersions = $null
560564 switch ($versionPart ) {
561565 ' 1.0' {
562566 $versions = @ (' v1.0.3705' )
@@ -578,7 +582,7 @@ function ConfigureBuildEnvironment {
578582 }
579583 ' 4.5.1' {
580584 $versions = @ (' v4.0.30319' )
581- $buildToolsVersions = @ (' 12.0' )
585+ $buildToolsVersions = @ (' 14.0 ' , ' 12.0' )
582586 }
583587 default {
584588 throw ($msgs.error_unknown_framework -f $versionPart , $framework )
@@ -617,11 +621,16 @@ function ConfigureBuildEnvironment {
617621 }
618622 }
619623 }
624+ $frameworkDirs = @ ()
620625 if ($buildToolsVersions -ne $null ) {
621- $frameworkDirs = @ ($buildToolsVersions | foreach { (Get-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\$_ " - Name $buildToolsKey ).$buildToolsKey })
626+ foreach ($ver in $buildToolsVersions ) {
627+ if (Test-Path " HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\$ver " ) {
628+ $frameworkDirs += (Get-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\$ver " - Name $buildToolsKey ).$buildToolsKey
629+ }
630+ }
622631 }
623632 $frameworkDirs = $frameworkDirs + @ ($versions | foreach { " $env: windir \Microsoft.NET\$bitness \$_ \" })
624-
633+
625634 for ($i = 0 ; $i -lt $frameworkDirs.Count ; $i ++ ) {
626635 $dir = $frameworkDirs [$i ]
627636 if ($dir -Match " \$\(Registry:HKEY_LOCAL_MACHINE(.*?)@(.*)\)" ) {
@@ -631,7 +640,7 @@ function ConfigureBuildEnvironment {
631640 $frameworkDirs [$i ] = $dir
632641 }
633642 }
634-
643+
635644 $frameworkDirs | foreach { Assert (test-path $_ - pathType Container) ($msgs.error_no_framework_install_dir_found -f $_ )}
636645
637646 $env: path = ($frameworkDirs -join " ;" ) + " ;$env: path "
@@ -738,7 +747,7 @@ function ResolveError
738747 }
739748}
740749
741- function WriteDocumentation {
750+ function WriteDocumentation ( $showDetailed ) {
742751 $currentContext = $psake.context.Peek ()
743752
744753 if ($currentContext.tasks.default ) {
@@ -747,7 +756,7 @@ function WriteDocumentation {
747756 $defaultTaskDependencies = @ ()
748757 }
749758
750- $currentContext.tasks.Keys | foreach-object {
759+ $docs = $ currentContext.tasks.Keys | foreach-object {
751760 if ($_ -eq " default" ) {
752761 return
753762 }
@@ -760,33 +769,41 @@ function WriteDocumentation {
760769 " Depends On" = $task.DependsOn -join " , "
761770 Default = if ($defaultTaskDependencies -contains $task.Name ) { $true }
762771 }
763- } | sort ' Name' | format-list - property Name, Alias, Description, " Depends On" , Default
772+ }
773+ if ($showDetailed ) {
774+ $docs | sort ' Name' | format-list - property Name, Alias, Description, " Depends On" , Default
775+ } else {
776+ $docs | sort ' Name' | format-table - autoSize - wrap - property Name, Alias, " Depends On" , Default , Description
777+ }
778+
764779}
765780
766781function WriteTaskTimeSummary ($invokePsakeDuration ) {
767- " -" * 70
768- " Build Time Report"
769- " -" * 70
770- $list = @ ()
771- $currentContext = $psake.context.Peek ()
772- while ($currentContext.executedTasks.Count -gt 0 ) {
773- $taskKey = $currentContext.executedTasks.Pop ()
774- $task = $currentContext.tasks .$taskKey
775- if ($taskKey -eq " default" ) {
776- continue
782+ if ($psake.context.count -gt 0 ) {
783+ " -" * 70
784+ " Build Time Report"
785+ " -" * 70
786+ $list = @ ()
787+ $currentContext = $psake.context.Peek ()
788+ while ($currentContext.executedTasks.Count -gt 0 ) {
789+ $taskKey = $currentContext.executedTasks.Pop ()
790+ $task = $currentContext.tasks .$taskKey
791+ if ($taskKey -eq " default" ) {
792+ continue
793+ }
794+ $list += new-object PSObject - property @ {
795+ Name = $task.Name ;
796+ Duration = $task.Duration
797+ }
777798 }
799+ [Array ]::Reverse($list )
778800 $list += new-object PSObject - property @ {
779- Name = $task .Name ;
780- Duration = $task .Duration
801+ Name = " Total: " ;
802+ Duration = $invokePsakeDuration
781803 }
804+ # using "out-string | where-object" to filter out the blank line that format-table prepends
805+ $list | format-table - autoSize - property Name, Duration | out-string - stream | where-object { $_ }
782806 }
783- [Array ]::Reverse($list )
784- $list += new-object PSObject - property @ {
785- Name = " Total:" ;
786- Duration = $invokePsakeDuration
787- }
788- # using "out-string | where-object" to filter out the blank line that format-table prepends
789- $list | format-table - autoSize - property Name, Duration | out-string - stream | where-object { $_ }
790807}
791808
792809DATA msgs {
@@ -821,7 +838,7 @@ convertfrom-stringdata @'
821838import-localizeddata - bindingvariable msgs - erroraction silentlycontinue
822839
823840$script :psake = @ {}
824- $psake.version = " 4.3 .1" # contains the current version of psake
841+ $psake.version = " 4.4 .1" # contains the current version of psake
825842$psake.context = new-object system.collections.stack # holds onto the current state of all variables
826843$psake.run_by_psake_build_tester = $false # indicates that build is being run by psake-BuildTester
827844$psake.config_default = new-object psobject - property @ {
@@ -840,4 +857,4 @@ $psake.build_script_dir = "" # contains a string with fully-qualified path to cu
840857
841858LoadConfiguration
842859
843- export-modulemember - function Invoke-psake , Invoke-Task , Task, Properties, Include, FormatTaskName, TaskSetup, TaskTearDown, Framework, Assert, Exec - variable psake
860+ export-modulemember - function Invoke-psake , Invoke-Task , Task, Properties, Include, FormatTaskName, TaskSetup, TaskTearDown, Framework, Assert, Exec - variable psake
0 commit comments