This repository has been archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psake.psm1
1313 lines (1071 loc) · 33.6 KB
/
psake.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# psake
# Copyright (c) 2010 James Kovacs
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#Requires -Version 2.0
DATA msgs
{
convertfrom-stringdata @'
error_invalid_task_name = Error: Task name should not be null or empty string
error_task_name_does_not_exist = Error: task [{0}] does not exist
error_circular_reference = Error: Circular reference found for task, {0}
error_missing_action_parameter = Error: Action parameter must be specified when using PreAction or PostAction parameters
error_corrupt_callstack = Error: CallStack was corrupt. Expected {0}, but got {1}.
error_invalid_framework = Error: Invalid .NET Framework version, {0}, specified
error_unknown_framework = Error: Unknown .NET Framework version, {0}, specified in {1}
error_unknown_pointersize = Error: Unknown pointer size ({0}) returned from System.IntPtr.
error_unknown_bitnesspart = Error: Unknown .NET Framework bitness, {0}, specified in {1}
error_no_framework_install_dir_found = Error: No .NET Framework installation directory found at {0}
error_bad_command = Error executing command: {0}
error_default_task_cannot_have_action = Error: 'default' task cannot specify an action
error_duplicate_task_name = Error: Task {0} has already been defined.
error_invalid_include_path = Error: Unable to include {0}. File not found.
error_build_file_not_found = Error: Could not find the build file, {0}.
error_no_default_task = Error: default task required
error_invalid_module_dir = "Unable to load modules from directory: {0}"
error_invalid_module_path = "Unable to load module at path: {0}"
error_loading_module = "Error loading module: {0}"
postcondition_failed = Error: Postcondition failed for {0}
precondition_was_false = Precondition was false not executing {0}
continue_on_error = Error in Task [{0}] {1}
build_success = Build Succeeded!
'@
}
import-localizeddata -bindingvariable msgs -erroraction silentlycontinue
#-- Private Module Functions
function Load-Configuration
{
$psake.config = new-object psobject -property @{
defaultbuildfilename="default.ps1";
tasknameformat="Executing {0}";
exitcode="1";
modules=(new-object psobject -property @{ autoload=$false })
}
if (test-path ".\psake-config.ps1")
{
try
{
. .\psake-config.ps1
}
catch
{
throw "Error Loading Configuration from psake-config.ps1: " + $_
}
}
}
function IsChildOfService
{
param
(
[int]$currentProcessID = $PID
)
$currentProcess = gwmi -Query "select * from win32_process where processid = '$currentProcessID'"
if ($currentProcess.ProcessID -eq 0) #System Idle Process
{
return $false
}
$service = Get-WmiObject -Class Win32_Service -Filter "ProcessId = '$currentProcessID'"
if ($service) # We are invoked by a windows service
{
return $true
}
else
{
$parentProcess = gwmi -Query "select * from win32_process where processid = '$($currentProcess.ParentProcessID)'"
return IsChildOfService $parentProcess.ProcessID
}
}
function InNestedScope
{
try
{
$vars = get-variable -scope 1
return $true
}
catch
{
return $false
}
}
function Configure-BuildEnvironment
{
if ($framework.Length -ne 3 -and $framework.Length -ne 6) {
throw ($msgs.error_invalid_framework -f $framework)
}
$versionPart = $framework.Substring(0,3)
$bitnessPart = $framework.Substring(3)
$versions = $null
switch ($versionPart)
{
'1.0' { $versions = @('v1.0.3705') }
'1.1' { $versions = @('v1.1.4322') }
'2.0' { $versions = @('v2.0.50727') }
'3.0' { $versions = @('v2.0.50727') }
'3.5' { $versions = @('v3.5','v2.0.50727') }
'4.0' { $versions = @('v4.0.30319') }
'WP7' { $versions = @('WP7')}
default { throw ($msgs.error_unknown_framework -f $versionPart,$framework) }
}
#tweaked by Christofer Löf for Windows Phone 7
$bitness = 'Framework'
$programFiles = ${env:ProgramFiles}
if($versionPart -ne '1.0' -and $versionPart -ne '1.1') {
switch ($bitnessPart)
{
'x86' {
$bitness = 'Framework'
$programFiles = ${env:ProgramFiles}
}
'x64' {
$bitness = 'Framework64'
$programFiles = ${env:ProgramFiles(x86)}
}
'' {
$ptrSize = [System.IntPtr]::Size
switch ($ptrSize)
{
4 {
$bitness = 'Framework'
$programFiles = ${env:ProgramFiles}
}
8 {
$bitness = 'Framework64'
$programFiles = ${env:ProgramFiles(x86)}
}
default { throw ($msgs.error_unknown_pointersize -f $ptrSize) }
}
}
default { throw ($msgs.error_unknown_bitnesspart -f $bitnessPart,$framework) }
}
}
if($versionPart -eq 'WP7'){
$frameworkDirs = @("$programFiles\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone\")
} else {
$frameworkDirs = $versions | foreach { "$env:windir\Microsoft.NET\$bitness\$_\" }
}
$frameworkDirs | foreach { Assert (test-path $_) ($msgs.error_no_framework_install_dir_found -f $_)}
$env:path = ($frameworkDirs -join ";") + ";$env:path"
#if any error occurs in a PS function then "stop" processing immediately
# this does not effect any external programs that return a non-zero exit code
$global:ErrorActionPreference = "Stop"
}
function Cleanup-Environment
{
if ($psake.context.Count -gt 0)
{
$currentContext = $psake.context.Peek()
$env:path = $currentContext.originalEnvPath
Set-Location $currentContext.originalDirectory
$global:ErrorActionPreference = $currentContext.originalErrorActionPreference
[void]$psake.context.Pop()
}
}
#borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx
function Resolve-Error($ErrorRecord=$Error[0])
{
$error_message = "`nErrorRecord:{0}ErrorRecord.InvocationInfo:{1}Exception:{2}"
$formatted_errorRecord = $ErrorRecord | format-list * -force | out-string
$formatted_invocationInfo = $ErrorRecord.InvocationInfo | format-list * -force | out-string
$formatted_exception = ""
$Exception = $ErrorRecord.Exception
for ($i = 0; $Exception; $i++, ($Exception = $Exception.InnerException))
{
$formatted_exception += ("$i" * 70) + "`n"
$formatted_exception += $Exception | format-list * -force | out-string
$formatted_exception += "`n"
}
return $error_message -f $formatted_errorRecord,$formatted_invocationInfo,$formatted_exception
}
function Write-Documentation
{
$currentContext = $psake.context.Peek()
$currentContext.tasks.Keys |
foreach-object {
if($_ -eq "default") { return }
$task = $currentContext.tasks.$_
new-object PsObject -property @{
Name = $task.Name
Description = $task.Description
"Depends On" = $task.DependsOn -join ", "
}
} |
Sort 'Name' |
Format-Table -Auto
}
function Write-TaskTimeSummary
{
"-"*70
"Build Time Report"
"-"*70
$list = @()
$currentContext = $psake.context.Peek()
while ($currentContext.executedTasks.Count -gt 0)
{
$taskKey = $currentContext.executedTasks.Pop()
$task = $currentContext.tasks.$taskKey
if($taskKey -eq "default")
{
continue
}
$list += New-Object PsObject -property @{Name=$task.Name; Duration = $task.Duration}
}
[Array]::Reverse($list)
$list += New-Object PsObject -property @{Name="Total:"; Duration=$stopwatch.Elapsed}
$list | Format-Table -Auto | Out-String -Stream | ? {$_} # using "Out-String -Stream" to filter out the blank line that Format-Table prepends
}
#-- Public Module Functions
function Invoke-Task
{
<#
.SYNOPSIS
This function allows you to call a target from another target
.DESCRIPTION
This is a function that will allow you to invoke a function from within another function
.PARAMETER taskName
The name of the task to execute
.EXAMPLE
invoke-task clean
This example calls "clean" task
.LINK
Assert
Invoke-psake
Task
Properties
Include
FormatTaskName
TaskSetup
TaskTearDown
#>
[CmdletBinding()]
param([Parameter(Position=0,Mandatory=1)][string]$taskName)
Assert $taskName ($msgs.error_invalid_task_name)
$taskKey = $taskName.ToLower()
$currentContext = $psake.context.Peek()
$tasks = $currentContext.tasks
$executedTasks = $currentContext.executedTasks
$callStack = $currentContext.callStack
Assert ($tasks.Contains($taskKey)) ($msgs.error_task_name_does_not_exist -f $taskName)
if ($executedTasks.Contains($taskKey)) { return }
Assert (!$callStack.Contains($taskKey)) ($msgs.error_circular_reference -f $taskName)
$callStack.Push($taskKey)
$task = $tasks.$taskKey
$precondition_is_valid = & $task.Precondition
if (!$precondition_is_valid)
{
$msgs.precondition_was_false -f $taskName
}
else
{
if ($taskKey -ne 'default')
{
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
if ($task.PreAction -or $task.PostAction)
{
Assert ($task.Action -ne $null) $msgs.error_missing_action_parameter
}
if ($task.Action)
{
try
{
foreach($childTask in $task.DependsOn)
{
Invoke-Task $childTask
}
$currentContext.currentTaskName = $taskName
& $currentContext.taskSetupScriptBlock
if ($task.PreAction)
{
& $task.PreAction
}
if ($currentContext.formatTaskName -is [ScriptBlock])
{
& $currentContext.formatTaskName $taskName
}
else
{
$currentContext.formatTaskName -f $taskName
}
& $task.Action
if ($task.PostAction)
{
& $task.PostAction
}
& $currentContext.taskTearDownScriptBlock
}
catch
{
if ($task.ContinueOnError)
{
"-"*70
$msgs.continue_on_error -f $taskName,$_
"-"*70
}
else
{
throw $_
}
}
} # if ($task.Action)
else
{
#no Action was specified but we still execute all the dependencies
foreach($childTask in $task.DependsOn)
{
Invoke-Task $childTask
}
}
$stopwatch.stop()
$task.Duration = $stopwatch.Elapsed
} # if ($taskKey -ne 'default')
else
{
foreach($childTask in $task.DependsOn)
{
Invoke-Task $childTask
}
}
Assert (& $task.Postcondition) ($msgs.postcondition_failed -f $taskName)
}
$poppedTaskKey = $callStack.Pop()
Assert ($poppedTaskKey -eq $taskKey) ($msgs.error_corrupt_callstack -f $taskKey,$poppedTaskKey)
$executedTasks.Push($taskKey)
}
function Exec
{
<#
.SYNOPSIS
Helper function for executing command-line programs.
.DESCRIPTION
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode to see if an error occcured.
If an error is detected then an exception is thrown. This function allows you to run command-line programs without
having to explicitly check fthe $lastexitcode variable.
.PARAMETER cmd
The scriptblock to execute. This scriptblock will typically contain the command-line invocation.
Required
.PARAMETER errorMessage
The error message used for the exception that is thrown.
Optional
.EXAMPLE
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
This example calls the svn command-line client.
.LINK
Assert
Invoke-psake
Task
Properties
Include
FormatTaskName
TaskSetup
TaskTearDown
#>
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0)
{
throw $errorMessage
}
}
function Assert
{
<#
.SYNOPSIS
Helper function for "Design by Contract" assertion checking.
.DESCRIPTION
This is a helper function that makes the code less noisy by eliminating many of the "if" statements
that are normally required to verify assumptions in the code.
.PARAMETER conditionToCheck
The boolean condition to evaluate
Required
.PARAMETER failureMessage
The error message used for the exception if the conditionToCheck parameter is false
Required
.EXAMPLE
Assert $false "This always throws an exception"
This example always throws an exception
.EXAMPLE
Assert ( ($i % 2) -eq 0 ) "%i is not an even number"
This exmaple may throw an exception if $i is not an even number
.LINK
Invoke-psake
Task
Properties
Include
FormatTaskName
TaskSetup
TaskTearDown
.NOTES
It might be necessary to wrap the condition with paranthesis to force PS to evaluate the condition
so that a boolean value is calculated and passed into the 'conditionToCheck' parameter.
Example:
Assert 1 -eq 2 "1 doesn't equal 2"
PS will pass 1 into the condtionToCheck variable and PS will look for a parameter called "eq" and
throw an exception with the following message "A parameter cannot be found that matches parameter name 'eq'"
The solution is to wrap the condition in () so that PS will evaluate it first.
Assert (1 -eq 2) "1 doesn't equal 2"
#>
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)]$conditionToCheck,
[Parameter(Position=1,Mandatory=1)]$failureMessage
)
if (!$conditionToCheck)
{
throw $failureMessage
}
}
function Task
{
<#
.SYNOPSIS
Defines a build task to be executed by psake
.DESCRIPTION
This function creates a 'task' object that will be used by the psake engine to execute a build task.
Note: There must be at least one task called 'default' in the build script
.PARAMETER Name
The name of the task
Required
.PARAMETER Action
A scriptblock containing the statements to execute
Optional
.PARAMETER PreAction
A scriptblock to be executed before the 'Action' scriptblock.
Note: This parameter is ignored if the 'Action' scriptblock is not defined.
Optional
.PARAMETER PostAction
A scriptblock to be executed after the 'Action' scriptblock.
Note: This parameter is ignored if the 'Action' scriptblock is not defined.
Optional
.PARAMETER Precondition
A scriptblock that is executed to determine if the task is executed or skipped.
This scriptblock should return $true or $false
Optional
.PARAMETER Postcondition
A scriptblock that is executed to determine if the task completed its job correctly.
An exception is thrown if the scriptblock returns $false.
Optional
.PARAMETER ContinueOnError
If this switch parameter is set then the task will not cause the build to fail when an exception is thrown
.PARAMETER Depends
An array of tasks that this task depends on. They will be executed before the current task is executed.
.PARAMETER Description
A description of the task.
.EXAMPLE
A sample build script is shown below:
task default -depends Test
task Test -depends Compile, Clean {
"This is a test"
}
task Compile -depends Clean {
"Compile"
}
task Clean {
"Clean"
}
The 'default' task is required and should not contain an 'Action' parameter.
It uses the 'depends' parameter to specify that 'Test' is a dependency
The 'Test' task uses the 'depends' parameter to specify that 'Compile' and 'Clean' are dependencies
The 'Compile' task depends on the 'Clean' task.
Note:
The 'Action' parameter is defaulted to the script block following the 'Clean' task.
The equivalent 'Test' task is shown below:
task Test -depends Compile, Clean -Action {
$testMessage
}
The output for the above sample build script is shown below:
Executing task, Clean...
Clean
Executing task, Compile...
Compile
Executing task, Test...
This is a test
Build Succeeded!
----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name Duration
---- --------
Clean 00:00:00.0065614
Compile 00:00:00.0133268
Test 00:00:00.0225964
Total: 00:00:00.0782496
.LINK
Invoke-psake
Properties
Include
FormatTaskName
TaskSetup
TaskTearDown
Assert
#>
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)]
[string]$name = $null,
[Parameter(Position=1,Mandatory=0)]
[scriptblock]$action = $null,
[Parameter(Position=2,Mandatory=0)]
[scriptblock]$preaction = $null,
[Parameter(Position=3,Mandatory=0)]
[scriptblock]$postaction = $null,
[Parameter(Position=4,Mandatory=0)]
[scriptblock]$precondition = {$true},
[Parameter(Position=5,Mandatory=0)]
[scriptblock]$postcondition = {$true},
[Parameter(Position=6,Mandatory=0)]
[switch]$continueOnError = $false,
[Parameter(Position=7,Mandatory=0)]
[string[]]$depends = @(),
[Parameter(Position=8,Mandatory=0)]
[string]$description = $null
)
if ($name -eq 'default')
{
Assert (!$action) ($msgs.error_default_task_cannot_have_action)
}
$newTask = @{
Name = $name
DependsOn = $depends
PreAction = $preaction
Action = $action
PostAction = $postaction
Precondition = $precondition
Postcondition = $postcondition
ContinueOnError = $continueOnError
Description = $description
Duration = 0
}
$taskKey = $name.ToLower()
$currentContext = $psake.context.Peek()
Assert (!$currentContext.tasks.ContainsKey($taskKey)) ($msgs.error_duplicate_task_name -f $name)
$currentContext.tasks.$taskKey = $newTask
}
function Properties
{
<#
.SYNOPSIS
Define a scriptblock that contains assignments to variables that will be available to all tasks in the build script
.DESCRIPTION
A build script may declare a "Properies" function which allows you to define
variables that will be available to all the "Task" functions in the build script.
.PARAMETER properties
The script block containing all the variable assignment statements
Required
.EXAMPLE
A sample build script is shown below:
Properties {
$build_dir = "c:\build"
$connection_string = "datasource=localhost;initial catalog=northwind;integrated security=sspi"
}
Task default -depends Test
Task Test -depends Compile, Clean {
}
Task Compile -depends Clean {
}
Task Clean {
}
.LINK
Invoke-psake
Task
Include
FormatTaskName
TaskSetup
TaskTearDown
Assert
.NOTES
You can have more than 1 "Properties" function defined in the script
#>
[CmdletBinding()]
param([Parameter(Position=0,Mandatory=1)][scriptblock]$properties)
$psake.context.Peek().properties += $properties
}
function Include
{
<#
.SYNOPSIS
Include the functions or code of another powershell script file into the current build script's scope
.DESCRIPTION
A build script may declare an "includes" function which allows you to define
a file containing powershell code to be included and added to the scope of
the currently running build script.
.PARAMETER fileNamePathToInclude
A string containing the path and name of the powershell file to include
Required
.EXAMPLE
A sample build script is shown below:
Include ".\build_utils.ps1"
Task default -depends Test
Task Test -depends Compile, Clean {
}
Task Compile -depends Clean {
}
Task Clean {
}
.LINK
Invoke-psake
Task
Properties
FormatTaskName
TaskSetup
TaskTearDown
Assert
.NOTES
You can have more than 1 "Include" function defined in the script
#>
[CmdletBinding()]
param([Parameter(Position=0,Mandatory=1)][string]$fileNamePathToInclude)
Assert (test-path $fileNamePathToInclude) ($msgs.error_invalid_include_path -f $fileNamePathToInclude)
$psake.context.Peek().includes.Enqueue((Resolve-Path $fileNamePathToInclude));
}
function FormatTaskName
{
<#
.SYNOPSIS
Allows you to define a format mask that will be used when psake displays
the task name
.DESCRIPTION
Allows you to define a format mask that will be used when psake displays
the task name. The default is "Executing task, {0}..."
.PARAMETER format
A string containing the format mask to use, it should contain a placeholder ({0})
that will be used to substitute the task name.
Required
.EXAMPLE
A sample build script is shown below:
FormatTaskName "[Task: {0}]"
Task default -depends Test
Task Test -depends Compile, Clean {
}
Task Compile -depends Clean {
}
Task Clean {
}
You should get the following output:
------------------------------------
[Task: Clean]
[Task: Compile]
[Task: Test]
Build Succeeded
----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name Duration
---- --------
Clean 00:00:00.0043477
Compile 00:00:00.0102130
Test 00:00:00.0182858
Total: 00:00:00.0698071
.LINK
Invoke-psake
Include
Task
Properties
TaskSetup
TaskTearDown
Assert
#>
[CmdletBinding()]
param([Parameter(Position=0,Mandatory=1)]$format)
$psake.context.Peek().formatTaskName = $format
}
function TaskSetup
{
<#
.SYNOPSIS
Adds a scriptblock that will be executed before each task
.DESCRIPTION
This function will accept a scriptblock that will be executed before each
task in the build script.
.PARAMETER include
A scriptblock to execute
Required
.EXAMPLE
A sample build script is shown below:
Task default -depends Test
Task Test -depends Compile, Clean {
}
Task Compile -depends Clean {
}
Task Clean {
}
TaskSetup {
"Running 'TaskSetup' for task $context.Peek().currentTaskName"
}
You should get the following output:
------------------------------------
Running 'TaskSetup' for task Clean
Executing task, Clean...
Running 'TaskSetup' for task Compile
Executing task, Compile...
Running 'TaskSetup' for task Test
Executing task, Test...
Build Succeeded
----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name Duration
---- --------
Clean 00:00:00.0054018
Compile 00:00:00.0123085
Test 00:00:00.0236915
Total: 00:00:00.0739437
.LINK
Invoke-psake
Include
Task
Properties
FormatTaskName
TaskTearDown
Assert
#>
[CmdletBinding()]
param([Parameter(Position=0,Mandatory=1)][scriptblock]$setup)
$psake.context.Peek().taskSetupScriptBlock = $setup
}
function TaskTearDown
{
<#
.SYNOPSIS
Adds a scriptblock that will be executed after each task
.DESCRIPTION
This function will accept a scriptblock that will be executed after each
task in the build script.
.PARAMETER include
A scriptblock to execute
Required
.EXAMPLE
A sample build script is shown below:
Task default -depends Test
Task Test -depends Compile, Clean {
}
Task Compile -depends Clean {
}
Task Clean {
}
TaskTearDown {
"Running 'TaskTearDown' for task $context.Peek().currentTaskName"
}
You should get the following output:
------------------------------------
Executing task, Clean...
Running 'TaskTearDown' for task Clean
Executing task, Compile...
Running 'TaskTearDown' for task Compile
Executing task, Test...
Running 'TaskTearDown' for task Test
Build Succeeded
----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name Duration
---- --------
Clean 00:00:00.0064555
Compile 00:00:00.0218902
Test 00:00:00.0309151
Total: 00:00:00.0858301
.LINK
Invoke-psake
Include
Task
Properties
FormatTaskName
TaskSetup
Assert
#>
[CmdletBinding()]
param([Parameter(Position=0,Mandatory=1)][scriptblock]$teardown)
$psake.context.Peek().taskTearDownScriptBlock = $teardown
}
function Invoke-psake
{
<#
.SYNOPSIS
Runs a psake build script.
.DESCRIPTION
This function runs a psake build script
.PARAMETER BuildFile
The psake build script to execute (default: default.ps1).
.PARAMETER TaskList
A comma-separated list of task names to execute
.PARAMETER Framework
The version of the .NET framework you want to build. You can append x86 or x64 to force a specific framework. If not specified, x86 or x64 will be detected based on the bitness of the PowerShell process.
Possible values: '1.0', '1.1', '2.0', '2.0x86', '2.0x64', '3.0', '3.0x86', '3.0x64', '3.5', '3.5x86', '3.5x64', '4.0', '4.0x86', '4.0x64'
Default = '3.5'
.PARAMETER Docs
Prints a list of tasks and their descriptions
.PARAMETER Parameters
A hashtable containing parameters to be passed into the current build script. These parameters will be processed before the 'Properties' function of the script is processed. This means you can access parameters from within the 'Properties' function!