Open joeypiccola opened 4 years ago
@joeypiccola tl:dr: It's an ordering issue in the way psake loads the tasks.
When you tell psake to load tasks from a module, it runs the psakeFile.ps1
provided in that module. That file will load the default properties including the default values in $PSBPreference.Build.Dependencies
. The tasks in that file are then loaded into the psake context (with whatever attributes are specified). psake then loads your psakeFile.ps1
that overrides $PSBPreference.Build.Dependencies
but it doesn't matter as those tasks have already been loaded into psake and their attributes are already set.
When you tell psake to load a task from a module, you can override things like -Depends
explicitly.
Try this:
task Build -FromModule PowerShellBuild -depends @('StageFiles', 'BuildHelp', 'BumpVersion')
task BumpVersion {
'Bump version'
}
This will give the behavior you want, but ideally we also want to way to do the same when modifying `$PSBPreference
.
@devblackops Thanks for the help, much appreciated.
but it doesn't matter as those tasks have already been loaded into psake and their attributes are already set
So what is the intended usage of PowerShellBuilds's $PSBPreference.Build.Dependencies
if not to append or override the default Build
task dependencies?
As for what you suggested trying, the following results in the task testTask
not running. Hopefully, I have understood you correctly in that by running task Build
I am interacting with the PowerShellBuild's task Build
.
task default -depends Test
task Test -FromModule PowerShellBuild -Version '0.3.0'
task Build -FromModule PowerShellBuild -Version '0.3.0' -depends @('StageFiles', 'BuildHelp', 'testTask')
task testTask {
'my test task'
}
OUTPUT
Task: BUILD TIME REPORT
Name Duration
---- --------
Init 00:00:00.170
Clean 00:00:00.008
StageFiles 00:00:00.181
GenerateMarkdown 00:00:02.547
GenerateMAML 00:00:01.219
BuildHelp 00:00:00.002
Build 00:00:00.000
Pester 00:00:07.390
Analyze 00:00:00.214
Test 00:00:00.001
Total: 00:00:11.834
This appears to still remain an issue. Was there a better way of handling the Shared Task dependencies?
I'm having the same issue. My project includes a .NET Framework DLL written in C# which needs to be compiled, and the output staged with the PowerShell module files prior to building the module itself. I was thinking a good way to do this would be to add my task as a dependency to Build but I'm unable to get my task to run when specifying it in $PSBPreference or in the -depends task parameter.
For now, I think I'll work around it by using a separate psakeFile and calling both from build.ps1.
@joeypiccola
Looks like you can change the task import order to make your 2nd example work:
task default -depends Test
task Build -FromModule PowerShellBuild -Version '0.6.1' -depends @('StageFiles', 'BuildHelp', 'testTask')
task Test -FromModule PowerShellBuild -Version '0.6.1'
task testTask{
'my test task'
}
Compared to your original (2nd) example, I swapped the order of task Build
and task Test
so the Build
with -depends comes first.
I assume this is related to the same ordering issue originally mentioned. So, a Task with overridden dependencies needs to be specified prior to importing another task that itself depends on the task with overridden dependencies.
@devblackops - being able to hook custom tasks into the build chain seems like a pretty common use case. Is this the correct method?
I have the task
BumpVersion
that I want theBuild
task to depend on. That said, I found$PSBPreference.Build.Dependencies
and have supplied the following array@('StageFiles', 'BuildHelp', 'BumpVersion')
. However,BumpVersion
never runs.StageFiles
andBuildHelp
do run.Expected Behavior
When running the
Build
task, additional dependencies listed in$PSBPreference.Build.Dependencies
should also run.Current Behavior
When running the
Build
task, additional dependencies listed in$PSBPreference.Build.Dependencies
do not run. Strangely enough, when supplying$PSBPreference.Build.Dependencies
with onlyBumpVersion
the default build task dependenciesStageFiles
andBuildHelp
still run making me think$PSBPreference.Build.Dependencies
is not even being correctly passed.Possible Solution
I've verified
$PSBPreference.Build.Dependencies
is being supplied to theBuild
task here: https://github.com/psake/PowerShellBuild/blob/11e1b94f22b295cfa7a6494bc7d0c25e2fb52864/PowerShellBuild/psakeFile.ps1#L54Steps to Reproduce (for bugs)
$PSBPreference.Build.Dependencies
in theproperties
block of apsakeFile.ps1
with the value of @('MyExtraBuildTask')psakeFile.ps1
e.g...Context
I have a few extra tasks that I want to run as part of the build. Specifically, a task that bumps the module version if it has not already been incremented and also a task that uploads test results to appveyor when the BuildSystem is appveyor.
Your Environment