I created two PowerShell files: build.ps1 and Get-Target.ps1

Oct 9, 2010 at 12:53 PM
Edited Oct 9, 2010 at 1:19 PM
PS c:\nupack> .\Get-BuildTarget.ps1 

Name                                                                                               
----                                                                                               
Go                                                                                                 
Build                                                                                              
RunTests                                                                                           
BuildPackages                                                                                      
CreateDropDirectories                                                                              
CopyExecutableOutputToDropDirectory                                                                
CopyVisualStudioAddInOutputToDropDirectory                                                         
CopyServerOutputToDropDirectory                                                                    
CopyLicenseToAllDirectories                                                                        
ILMergeTheExecutable                                                                               
RunIntegrationTests                                                                                


PS c:\nupack> .\Get-BuildTarget.ps1 inte | .\build.ps1

  Results               Top Level Tests
  -------               ---------------
  Passed                NuPack.Test.Integration.NuPackCommandLine.NuPackCommandLineTest.WhenNotPassingArgumentsAndThereAreNoNuSpecFilesItShouldError
  Passed                NuPack.Test.Integration.NuPackCommandLine.NuPackCommandLineTest.WhenNotPassingArgumentsAndThereIsOneNuSpecFileItShouldExecuteTheFile
  Passed                NuPack.Test.Integration.NuPackCommandLine.NuPackCommandLineTest.WhenNotPassingArgumentsThereAreTwoNuSpecFilesItShouldError
  3/3 test(s) Passed

  Summary
  -------
  Test Run Completed.    Passed  3
  
  ---------
    Total   3

  Test Settings: NuPack.Test.Integration
Done Building Project "c:\nupack\NuPack.Test.Integration\NuPack.Test.Integration.csproj" (RunIntegrationTests target(s)).

Done Building Project "c:\nupack\Build\Build.proj" (RunIntegrationTests target(s)).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.98

Get-BuildTarget.ps1

param($targetName, $csproj = ".\Build\Build.proj")

$xml = [xml] (Get-Content $csproj)

$xml.Project.Target |
    Where {$_.Name -match $targetName} | select Name

Build.ps1

param(
    [Parameter(ValueFromPipelineByPropertyName=$true)]
    $name="go"
)

Process {
    $msbuild = "$env:windir\Microsoft.NET\Framework\v4.0.30319\msbuild"
    & $msbuild Build\Build.proj /t:$name
}