by Oliver
31. July 2012 17:27
Developing our web application www.marinas.info using Orchard CMS, I often find myself at the command prompt to run different sets of build actions:
- in place compilation
- packaging for stage
- deploying to a local app instance
- running spec tests
- …
Sometimes I have trouble remembering the correct target name, so today I set out to attack this simple problem (displaying the names of all target defined in our build script) using Powershell. I’ve long waited for a good occasion to get my hands on it – today was finally the day.
Following this inspiring walk-through by the Windows Scripting guy to parse an XML file, I made my first firm steps in Powershell, and after some guesswork I came up with this one-liner that omits the definition of a variable:
[xml](Get-Content C:\Projects\discoverize\Discoverize.proj) | Foreach-Object {$_.project.target} | % {$_.Name} | sort
It might help to know that % is an alias for the Foreach-Object cmdlet, and $_ references the item currently piped in.
I saved this into a file that from now on I can simply call to get an up-to-date list of build target names.