0

I have the following simple psakefile.ps1:

Task Build {
    Write-Host "Build"
}

When I invoke it using my build.ps1:

nuget install psake -version 4.9.0
Import-Module .\psake.4.9.0\tools\psake\psake.psm1 -Force
Invoke-psake psakefile.ps1

I get an exception stating a 'default' task is required. I assumed this means I can specify 'Build' on the command line, or provide a task called 'default', so my psakefile.ps1 becomes:

Task Build {
    Write-Host "Build"
}

Task default -Depends Build {
    # Nothing to do, only here as a placeholder
}

But now I get a very weird exception:

Exception: Assert: '{0} references a shared task from module {1} and cannot have an action.

If I put any actual code in the 'default' task, I just get the exception saying I need a default task again.

Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220

1 Answers1

0

Yes, sure enough I'd already worked it out, and since I couldn't find the actual exception message on the internet, I figured I'd put an answer here so there is one somewhere (probably my future self will wind up reading this one day).

The problem is simply that when defining the default task, you can't put the ScriptBlock. Instead, define it simply as:

Task default -Depends Build
Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220