views:

271

answers:

1

We use NAnt extensively for our build system. Recently, I've written a couple PowerShell Cmdlets to perform a few database related things. At first, the intent of these Cmdlets was not to necessarily run within our build process. However, this has recently become a need and we would like to run a few of these Cmdlets from our NAnt based build process.

These Cmdlets are written in C# and we have a SnapIn for them (if that matters at all).

A few ideas:

  • Use the exec task to call PowerShell? (not sure how this would work though)
  • Write a custom NAnt task that references and uses the Cmdlet?

What might be a good way to do this?

+2  A: 

You could certainly use the exec task, setting the program attribute to powershell.exe and passing in the commandline something like "-Command { }".

Alternatively, you could certainly create a custom NAnt task that internally uses the powershell hosting APIs to execute your cmdlets or scripts. There's a simple example of this (using the PS v1 APIs) here.

tomasr