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:
What might be a good way to do this?
You can use the below exec task in your nant script to call your ps cmdlets.
<exec program="powershell" workingdir="${BuildManagementDir}" verbose="true">
<arg value="-noprofile"/>
<arg value="-nologo"/>
<arg value="-noninteractive"/>
<arg value="-command"/>
<arg value=".\xyz.ps1"/>
</exec>
You could certainly use the exec task, setting the program attribute to powershell.exe and passing in the command line something like "-Command { }".
Alternatively, you could 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With