How to use psake from a batch file?
Asked Answered
T

2

7

What I want is a one file I can double-click that will run the required build process using psake.

I'm new to psake and PowerShell so be gentle :-).

What I have now are 3 files:

File 1: Build.bat

PowerShell -ExecutionPolicy Unrestricted -File .\Build.ps1 %1

File 2: Build.ps1

Import-Module .\psake.psm1
Invoke-psake .\BuildTasks.ps1 $args

File 3: BuildTasks.ps1

task default -depends Verify, Joe

task Verify {
    write-host "hello from Verify!"
}

task Joe {
    write-host "hello from Joe"
}

Is there anyway to merge Build.ps1 and BuildTasks.ps1 into one file?

Tarrsus answered 8/12, 2009 at 8:28 Comment(0)
C
8

You should be able to do this with

powershell -Command "& {Import-Module .\psake.psm1; Invoke-psake .\BuildTasks.ps1 %*}"

which gets rid of the build.ps1 file.

Compensate answered 8/12, 2009 at 8:35 Comment(1)
Johannes. Thanks heaps. Just one all fix. %1 is required instead of $args. PowerShell -ExecutionPolicy Unrestricted -Command "& {Import-Module .\psake.psm1; Invoke-psake .\BuildTasks.ps1 %1}"Tarrsus
T
1

Psake comes with a powershell script "psake.ps1" which wraps the call for you. It looks like:

import-module .\psake.psm1
invoke-psake @args
remove-module psake

So your batch script looks like

powershell {path-to-module}\psake.ps1 .\buildTasks.ps1
Tacklind answered 31/8, 2010 at 13:7 Comment(1)
the psake.ps1 file you mentioned works fine for passing tasks into the invoke-psake call but the moment you attempt to pass hashtables (the -parameters and -properties arguments) it fails. At least I haven't been able to get it to work.Improbity

© 2022 - 2024 — McMap. All rights reserved.