Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional Build task dependencies listed in $PSBPreference.Build.Dependencies do not run. #37

Open
joeypiccola opened this issue Sep 25, 2019 · 5 comments

Comments

@joeypiccola
Copy link
Contributor

I have the task BumpVersion that I want the Build 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 and BuildHelp 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 only BumpVersion the default build task dependencies StageFiles and BuildHelp 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 the Build task here:

task Build -depends $PSBPreference.Build.Dependencies -description 'Builds module and generate help documentation'

Steps to Reproduce (for bugs)

  1. simply set $PSBPreference.Build.Dependencies in the properties block of a psakeFile.ps1 with the value of @('MyExtraBuildTask')
  2. create a task in the psakeFile.ps1 e.g...
task MyExtraBuildTask {
    "doing extra things"
}
  1. run build.ps1

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

  • Module version used:
    PowerShellBuild = 0.3.0
    Psake = 4.8.0
  • Operating System and PowerShell version:
    MacOS 10.14.6
    PowerShell = 6.2.0
@devblackops
Copy link
Member

@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`.

@joeypiccola
Copy link
Contributor Author

@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

@taalmahret
Copy link

This appears to still remain an issue. Was there a better way of handling the Shared Task dependencies?

@joshooaj
Copy link
Contributor

joshooaj commented Sep 1, 2021

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.

@rdavisunr
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants