& "$THIS_SCRIPTS_DIRECTORY_PATH\New-NuGetPackage.ps1" -PushOptions "$pushOptions" `
-Verbose -ProjectFilePath $project -PO "$packOptions" -NPFPPTNG
So if I provide the command line above in PowerShell the call works correctly.
If I try something like this:
if ($NoPromptForPushPackageToNuGetGallery) {
$xtraOptions += " -NPFPPTNG "
}
& "$THIS_SCRIPTS_DIRECTORY_PATH\New-NuGetPackage.ps1" -PushOptions "$pushOptions" `
-Verbose -ProjectFilePath $project -PO "$packOptions" $xtraOptions
this fails. How can I pass a switch in a variable?
You can use splatting:
If
$xtraOptions
is just an empty hashtable,@xtraOptions
will simply have no effect on the parameters passed.You could also push all the parameters into the splatting table with a conditional value: